sparc: tsb must be flushed before tlb
[pandora-kernel.git] / drivers / edac / sb_edac.c
1 /* Intel Sandy Bridge -EN/-EP/-EX Memory Controller kernel module
2  *
3  * This driver supports the memory controllers found on the Intel
4  * processor family Sandy Bridge.
5  *
6  * This file may be distributed under the terms of the
7  * GNU General Public License version 2 only.
8  *
9  * Copyright (c) 2011 by:
10  *       Mauro Carvalho Chehab <mchehab@redhat.com>
11  */
12
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/pci.h>
16 #include <linux/pci_ids.h>
17 #include <linux/slab.h>
18 #include <linux/delay.h>
19 #include <linux/edac.h>
20 #include <linux/mmzone.h>
21 #include <linux/smp.h>
22 #include <linux/bitmap.h>
23 #include <asm/processor.h>
24 #include <asm/mce.h>
25
26 #include "edac_core.h"
27
28 /* Static vars */
29 static LIST_HEAD(sbridge_edac_list);
30 static DEFINE_MUTEX(sbridge_edac_lock);
31 static int probed;
32
33 /*
34  * Alter this version for the module when modifications are made
35  */
36 #define SBRIDGE_REVISION    " Ver: 1.0.0 "
37 #define EDAC_MOD_STR      "sbridge_edac"
38
39 /*
40  * Debug macros
41  */
42 #define sbridge_printk(level, fmt, arg...)                      \
43         edac_printk(level, "sbridge", fmt, ##arg)
44
45 #define sbridge_mc_printk(mci, level, fmt, arg...)              \
46         edac_mc_chipset_printk(mci, level, "sbridge", fmt, ##arg)
47
48 /*
49  * Get a bit field at register value <v>, from bit <lo> to bit <hi>
50  */
51 #define GET_BITFIELD(v, lo, hi) \
52         (((v) & ((1ULL << ((hi) - (lo) + 1)) - 1) << (lo)) >> (lo))
53
54 /*
55  * sbridge Memory Controller Registers
56  */
57
58 /*
59  * FIXME: For now, let's order by device function, as it makes
60  * easier for driver's development proccess. This table should be
61  * moved to pci_id.h when submitted upstream
62  */
63 #define PCI_DEVICE_ID_INTEL_SBRIDGE_SAD0        0x3cf4  /* 12.6 */
64 #define PCI_DEVICE_ID_INTEL_SBRIDGE_SAD1        0x3cf6  /* 12.7 */
65 #define PCI_DEVICE_ID_INTEL_SBRIDGE_BR          0x3cf5  /* 13.6 */
66 #define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0     0x3ca0  /* 14.0 */
67 #define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA      0x3ca8  /* 15.0 */
68 #define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_RAS     0x3c71  /* 15.1 */
69 #define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD0    0x3caa  /* 15.2 */
70 #define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD1    0x3cab  /* 15.3 */
71 #define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD2    0x3cac  /* 15.4 */
72 #define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD3    0x3cad  /* 15.5 */
73 #define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_DDRIO   0x3cb8  /* 17.0 */
74
75         /*
76          * Currently, unused, but will be needed in the future
77          * implementations, as they hold the error counters
78          */
79 #define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_ERR0    0x3c72  /* 16.2 */
80 #define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_ERR1    0x3c73  /* 16.3 */
81 #define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_ERR2    0x3c76  /* 16.6 */
82 #define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_ERR3    0x3c77  /* 16.7 */
83
84 /* Devices 12 Function 6, Offsets 0x80 to 0xcc */
85 static const u32 dram_rule[] = {
86         0x80, 0x88, 0x90, 0x98, 0xa0,
87         0xa8, 0xb0, 0xb8, 0xc0, 0xc8,
88 };
89 #define MAX_SAD         ARRAY_SIZE(dram_rule)
90
91 #define SAD_LIMIT(reg)          ((GET_BITFIELD(reg, 6, 25) << 26) | 0x3ffffff)
92 #define DRAM_ATTR(reg)          GET_BITFIELD(reg, 2,  3)
93 #define INTERLEAVE_MODE(reg)    GET_BITFIELD(reg, 1,  1)
94 #define DRAM_RULE_ENABLE(reg)   GET_BITFIELD(reg, 0,  0)
95
96 static char *get_dram_attr(u32 reg)
97 {
98         switch(DRAM_ATTR(reg)) {
99                 case 0:
100                         return "DRAM";
101                 case 1:
102                         return "MMCFG";
103                 case 2:
104                         return "NXM";
105                 default:
106                         return "unknown";
107         }
108 }
109
110 static const u32 interleave_list[] = {
111         0x84, 0x8c, 0x94, 0x9c, 0xa4,
112         0xac, 0xb4, 0xbc, 0xc4, 0xcc,
113 };
114 #define MAX_INTERLEAVE  ARRAY_SIZE(interleave_list)
115
116 #define SAD_PKG0(reg)           GET_BITFIELD(reg, 0, 2)
117 #define SAD_PKG1(reg)           GET_BITFIELD(reg, 3, 5)
118 #define SAD_PKG2(reg)           GET_BITFIELD(reg, 8, 10)
119 #define SAD_PKG3(reg)           GET_BITFIELD(reg, 11, 13)
120 #define SAD_PKG4(reg)           GET_BITFIELD(reg, 16, 18)
121 #define SAD_PKG5(reg)           GET_BITFIELD(reg, 19, 21)
122 #define SAD_PKG6(reg)           GET_BITFIELD(reg, 24, 26)
123 #define SAD_PKG7(reg)           GET_BITFIELD(reg, 27, 29)
124
125 static inline int sad_pkg(u32 reg, int interleave)
126 {
127         switch (interleave) {
128         case 0:
129                 return SAD_PKG0(reg);
130         case 1:
131                 return SAD_PKG1(reg);
132         case 2:
133                 return SAD_PKG2(reg);
134         case 3:
135                 return SAD_PKG3(reg);
136         case 4:
137                 return SAD_PKG4(reg);
138         case 5:
139                 return SAD_PKG5(reg);
140         case 6:
141                 return SAD_PKG6(reg);
142         case 7:
143                 return SAD_PKG7(reg);
144         default:
145                 return -EINVAL;
146         }
147 }
148
149 /* Devices 12 Function 7 */
150
151 #define TOLM            0x80
152 #define TOHM            0x84
153
154 #define GET_TOLM(reg)           ((GET_BITFIELD(reg, 0,  3) << 28) | 0x3ffffff)
155 #define GET_TOHM(reg)           ((GET_BITFIELD(reg, 0, 20) << 25) | 0x3ffffff)
156
157 /* Device 13 Function 6 */
158
159 #define SAD_TARGET      0xf0
160
161 #define SOURCE_ID(reg)          GET_BITFIELD(reg, 9, 11)
162
163 #define SAD_CONTROL     0xf4
164
165 #define NODE_ID(reg)            GET_BITFIELD(reg, 0, 2)
166
167 /* Device 14 function 0 */
168
169 static const u32 tad_dram_rule[] = {
170         0x40, 0x44, 0x48, 0x4c,
171         0x50, 0x54, 0x58, 0x5c,
172         0x60, 0x64, 0x68, 0x6c,
173 };
174 #define MAX_TAD ARRAY_SIZE(tad_dram_rule)
175
176 #define TAD_LIMIT(reg)          ((GET_BITFIELD(reg, 12, 31) << 26) | 0x3ffffff)
177 #define TAD_SOCK(reg)           GET_BITFIELD(reg, 10, 11)
178 #define TAD_CH(reg)             GET_BITFIELD(reg,  8,  9)
179 #define TAD_TGT3(reg)           GET_BITFIELD(reg,  6,  7)
180 #define TAD_TGT2(reg)           GET_BITFIELD(reg,  4,  5)
181 #define TAD_TGT1(reg)           GET_BITFIELD(reg,  2,  3)
182 #define TAD_TGT0(reg)           GET_BITFIELD(reg,  0,  1)
183
184 /* Device 15, function 0 */
185
186 #define MCMTR                   0x7c
187
188 #define IS_ECC_ENABLED(mcmtr)           GET_BITFIELD(mcmtr, 2, 2)
189 #define IS_LOCKSTEP_ENABLED(mcmtr)      GET_BITFIELD(mcmtr, 1, 1)
190 #define IS_CLOSE_PG(mcmtr)              GET_BITFIELD(mcmtr, 0, 0)
191
192 /* Device 15, function 1 */
193
194 #define RASENABLES              0xac
195 #define IS_MIRROR_ENABLED(reg)          GET_BITFIELD(reg, 0, 0)
196
197 /* Device 15, functions 2-5 */
198
199 static const int mtr_regs[] = {
200         0x80, 0x84, 0x88,
201 };
202
203 #define RANK_DISABLE(mtr)               GET_BITFIELD(mtr, 16, 19)
204 #define IS_DIMM_PRESENT(mtr)            GET_BITFIELD(mtr, 14, 14)
205 #define RANK_CNT_BITS(mtr)              GET_BITFIELD(mtr, 12, 13)
206 #define RANK_WIDTH_BITS(mtr)            GET_BITFIELD(mtr, 2, 4)
207 #define COL_WIDTH_BITS(mtr)             GET_BITFIELD(mtr, 0, 1)
208
209 static const u32 tad_ch_nilv_offset[] = {
210         0x90, 0x94, 0x98, 0x9c,
211         0xa0, 0xa4, 0xa8, 0xac,
212         0xb0, 0xb4, 0xb8, 0xbc,
213 };
214 #define CHN_IDX_OFFSET(reg)             GET_BITFIELD(reg, 28, 29)
215 #define TAD_OFFSET(reg)                 (GET_BITFIELD(reg,  6, 25) << 26)
216
217 static const u32 rir_way_limit[] = {
218         0x108, 0x10c, 0x110, 0x114, 0x118,
219 };
220 #define MAX_RIR_RANGES ARRAY_SIZE(rir_way_limit)
221
222 #define IS_RIR_VALID(reg)       GET_BITFIELD(reg, 31, 31)
223 #define RIR_WAY(reg)            GET_BITFIELD(reg, 28, 29)
224 #define RIR_LIMIT(reg)          ((GET_BITFIELD(reg,  1, 10) << 29)| 0x1fffffff)
225
226 #define MAX_RIR_WAY     8
227
228 static const u32 rir_offset[MAX_RIR_RANGES][MAX_RIR_WAY] = {
229         { 0x120, 0x124, 0x128, 0x12c, 0x130, 0x134, 0x138, 0x13c },
230         { 0x140, 0x144, 0x148, 0x14c, 0x150, 0x154, 0x158, 0x15c },
231         { 0x160, 0x164, 0x168, 0x16c, 0x170, 0x174, 0x178, 0x17c },
232         { 0x180, 0x184, 0x188, 0x18c, 0x190, 0x194, 0x198, 0x19c },
233         { 0x1a0, 0x1a4, 0x1a8, 0x1ac, 0x1b0, 0x1b4, 0x1b8, 0x1bc },
234 };
235
236 #define RIR_RNK_TGT(reg)                GET_BITFIELD(reg, 16, 19)
237 #define RIR_OFFSET(reg)         GET_BITFIELD(reg,  2, 14)
238
239 /* Device 16, functions 2-7 */
240
241 /*
242  * FIXME: Implement the error count reads directly
243  */
244
245 static const u32 correrrcnt[] = {
246         0x104, 0x108, 0x10c, 0x110,
247 };
248
249 #define RANK_ODD_OV(reg)                GET_BITFIELD(reg, 31, 31)
250 #define RANK_ODD_ERR_CNT(reg)           GET_BITFIELD(reg, 16, 30)
251 #define RANK_EVEN_OV(reg)               GET_BITFIELD(reg, 15, 15)
252 #define RANK_EVEN_ERR_CNT(reg)          GET_BITFIELD(reg,  0, 14)
253
254 static const u32 correrrthrsld[] = {
255         0x11c, 0x120, 0x124, 0x128,
256 };
257
258 #define RANK_ODD_ERR_THRSLD(reg)        GET_BITFIELD(reg, 16, 30)
259 #define RANK_EVEN_ERR_THRSLD(reg)       GET_BITFIELD(reg,  0, 14)
260
261
262 /* Device 17, function 0 */
263
264 #define RANK_CFG_A              0x0328
265
266 #define IS_RDIMM_ENABLED(reg)           GET_BITFIELD(reg, 11, 11)
267
268 /*
269  * sbridge structs
270  */
271
272 #define NUM_CHANNELS    4
273 #define MAX_DIMMS       3               /* Max DIMMS per channel */
274
275 struct sbridge_info {
276         u32     mcmtr;
277 };
278
279 struct sbridge_channel {
280         u32             ranks;
281         u32             dimms;
282 };
283
284 struct pci_id_descr {
285         int                     dev;
286         int                     func;
287         int                     dev_id;
288         int                     optional;
289 };
290
291 struct pci_id_table {
292         const struct pci_id_descr       *descr;
293         int                             n_devs;
294 };
295
296 struct sbridge_dev {
297         struct list_head        list;
298         u8                      bus, mc;
299         u8                      node_id, source_id;
300         struct pci_dev          **pdev;
301         int                     n_devs;
302         struct mem_ctl_info     *mci;
303 };
304
305 struct sbridge_pvt {
306         struct pci_dev          *pci_ta, *pci_ddrio, *pci_ras;
307         struct pci_dev          *pci_sad0, *pci_sad1, *pci_ha0;
308         struct pci_dev          *pci_br;
309         struct pci_dev          *pci_tad[NUM_CHANNELS];
310
311         struct sbridge_dev      *sbridge_dev;
312
313         struct sbridge_info     info;
314         struct sbridge_channel  channel[NUM_CHANNELS];
315
316         int                     csrow_map[NUM_CHANNELS][MAX_DIMMS];
317
318         /* Memory type detection */
319         bool                    is_mirrored, is_lockstep, is_close_pg;
320
321         /* Fifo double buffers */
322         struct mce              mce_entry[MCE_LOG_LEN];
323         struct mce              mce_outentry[MCE_LOG_LEN];
324
325         /* Fifo in/out counters */
326         unsigned                mce_in, mce_out;
327
328         /* Count indicator to show errors not got */
329         unsigned                mce_overrun;
330
331         /* Memory description */
332         u64                     tolm, tohm;
333 };
334
335 #define PCI_DESCR(device, function, device_id)  \
336         .dev = (device),                        \
337         .func = (function),                     \
338         .dev_id = (device_id)
339
340 static const struct pci_id_descr pci_dev_descr_sbridge[] = {
341                 /* Processor Home Agent */
342         { PCI_DESCR(14, 0, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0)         },
343
344                 /* Memory controller */
345         { PCI_DESCR(15, 0, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)          },
346         { PCI_DESCR(15, 1, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_RAS)         },
347         { PCI_DESCR(15, 2, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD0)        },
348         { PCI_DESCR(15, 3, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD1)        },
349         { PCI_DESCR(15, 4, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD2)        },
350         { PCI_DESCR(15, 5, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD3)        },
351         { PCI_DESCR(17, 0, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_DDRIO)       },
352
353                 /* System Address Decoder */
354         { PCI_DESCR(12, 6, PCI_DEVICE_ID_INTEL_SBRIDGE_SAD0)            },
355         { PCI_DESCR(12, 7, PCI_DEVICE_ID_INTEL_SBRIDGE_SAD1)            },
356
357                 /* Broadcast Registers */
358         { PCI_DESCR(13, 6, PCI_DEVICE_ID_INTEL_SBRIDGE_BR)              },
359 };
360
361 #define PCI_ID_TABLE_ENTRY(A) { .descr=A, .n_devs = ARRAY_SIZE(A) }
362 static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
363         PCI_ID_TABLE_ENTRY(pci_dev_descr_sbridge),
364         {0,}                    /* 0 terminated list. */
365 };
366
367 /*
368  *      pci_device_id   table for which devices we are looking for
369  */
370 static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
371         {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
372         {0,}                    /* 0 terminated list. */
373 };
374
375
376 /****************************************************************************
377                         Anciliary status routines
378  ****************************************************************************/
379
380 static inline int numrank(u32 mtr)
381 {
382         int ranks = (1 << RANK_CNT_BITS(mtr));
383
384         if (ranks > 4) {
385                 debugf0("Invalid number of ranks: %d (max = 4) raw value = %x (%04x)",
386                         ranks, (unsigned int)RANK_CNT_BITS(mtr), mtr);
387                 return -EINVAL;
388         }
389
390         return ranks;
391 }
392
393 static inline int numrow(u32 mtr)
394 {
395         int rows = (RANK_WIDTH_BITS(mtr) + 12);
396
397         if (rows < 13 || rows > 18) {
398                 debugf0("Invalid number of rows: %d (should be between 14 and 17) raw value = %x (%04x)",
399                         rows, (unsigned int)RANK_WIDTH_BITS(mtr), mtr);
400                 return -EINVAL;
401         }
402
403         return 1 << rows;
404 }
405
406 static inline int numcol(u32 mtr)
407 {
408         int cols = (COL_WIDTH_BITS(mtr) + 10);
409
410         if (cols > 12) {
411                 debugf0("Invalid number of cols: %d (max = 4) raw value = %x (%04x)",
412                         cols, (unsigned int)COL_WIDTH_BITS(mtr), mtr);
413                 return -EINVAL;
414         }
415
416         return 1 << cols;
417 }
418
419 static struct sbridge_dev *get_sbridge_dev(u8 bus)
420 {
421         struct sbridge_dev *sbridge_dev;
422
423         list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) {
424                 if (sbridge_dev->bus == bus)
425                         return sbridge_dev;
426         }
427
428         return NULL;
429 }
430
431 static struct sbridge_dev *alloc_sbridge_dev(u8 bus,
432                                            const struct pci_id_table *table)
433 {
434         struct sbridge_dev *sbridge_dev;
435
436         sbridge_dev = kzalloc(sizeof(*sbridge_dev), GFP_KERNEL);
437         if (!sbridge_dev)
438                 return NULL;
439
440         sbridge_dev->pdev = kzalloc(sizeof(*sbridge_dev->pdev) * table->n_devs,
441                                    GFP_KERNEL);
442         if (!sbridge_dev->pdev) {
443                 kfree(sbridge_dev);
444                 return NULL;
445         }
446
447         sbridge_dev->bus = bus;
448         sbridge_dev->n_devs = table->n_devs;
449         list_add_tail(&sbridge_dev->list, &sbridge_edac_list);
450
451         return sbridge_dev;
452 }
453
454 static void free_sbridge_dev(struct sbridge_dev *sbridge_dev)
455 {
456         list_del(&sbridge_dev->list);
457         kfree(sbridge_dev->pdev);
458         kfree(sbridge_dev);
459 }
460
461 /****************************************************************************
462                         Memory check routines
463  ****************************************************************************/
464 static struct pci_dev *get_pdev_slot_func(u8 bus, unsigned slot,
465                                           unsigned func)
466 {
467         struct sbridge_dev *sbridge_dev = get_sbridge_dev(bus);
468         int i;
469
470         if (!sbridge_dev)
471                 return NULL;
472
473         for (i = 0; i < sbridge_dev->n_devs; i++) {
474                 if (!sbridge_dev->pdev[i])
475                         continue;
476
477                 if (PCI_SLOT(sbridge_dev->pdev[i]->devfn) == slot &&
478                     PCI_FUNC(sbridge_dev->pdev[i]->devfn) == func) {
479                         debugf1("Associated %02x.%02x.%d with %p\n",
480                                 bus, slot, func, sbridge_dev->pdev[i]);
481                         return sbridge_dev->pdev[i];
482                 }
483         }
484
485         return NULL;
486 }
487
488 /**
489  * sbridge_get_active_channels() - gets the number of channels and csrows
490  * bus:         Device bus
491  * @channels:   Number of channels that will be returned
492  * @csrows:     Number of csrows found
493  *
494  * Since EDAC core needs to know in advance the number of available channels
495  * and csrows, in order to allocate memory for csrows/channels, it is needed
496  * to run two similar steps. At the first step, implemented on this function,
497  * it checks the number of csrows/channels present at one socket, identified
498  * by the associated PCI bus.
499  * this is used in order to properly allocate the size of mci components.
500  * Note: one csrow is one dimm.
501  */
502 static int sbridge_get_active_channels(const u8 bus, unsigned *channels,
503                                       unsigned *csrows)
504 {
505         struct pci_dev *pdev = NULL;
506         int i, j;
507         u32 mcmtr;
508
509         *channels = 0;
510         *csrows = 0;
511
512         pdev = get_pdev_slot_func(bus, 15, 0);
513         if (!pdev) {
514                 sbridge_printk(KERN_ERR, "Couldn't find PCI device "
515                                         "%2x.%02d.%d!!!\n",
516                                         bus, 15, 0);
517                 return -ENODEV;
518         }
519
520         pci_read_config_dword(pdev, MCMTR, &mcmtr);
521         if (!IS_ECC_ENABLED(mcmtr)) {
522                 sbridge_printk(KERN_ERR, "ECC is disabled. Aborting\n");
523                 return -ENODEV;
524         }
525
526         for (i = 0; i < NUM_CHANNELS; i++) {
527                 u32 mtr;
528
529                 /* Device 15 functions 2 - 5  */
530                 pdev = get_pdev_slot_func(bus, 15, 2 + i);
531                 if (!pdev) {
532                         sbridge_printk(KERN_ERR, "Couldn't find PCI device "
533                                                  "%2x.%02d.%d!!!\n",
534                                                  bus, 15, 2 + i);
535                         return -ENODEV;
536                 }
537                 (*channels)++;
538
539                 for (j = 0; j < ARRAY_SIZE(mtr_regs); j++) {
540                         pci_read_config_dword(pdev, mtr_regs[j], &mtr);
541                         debugf1("Bus#%02x channel #%d  MTR%d = %x\n", bus, i, j, mtr);
542                         if (IS_DIMM_PRESENT(mtr))
543                                 (*csrows)++;
544                 }
545         }
546
547         debugf0("Number of active channels: %d, number of active dimms: %d\n",
548                 *channels, *csrows);
549
550         return 0;
551 }
552
553 static int get_dimm_config(const struct mem_ctl_info *mci)
554 {
555         struct sbridge_pvt *pvt = mci->pvt_info;
556         struct csrow_info *csr;
557         unsigned i, j, banks, ranks, rows, cols, npages;
558         u64 size;
559         int csrow = 0;
560         unsigned long last_page = 0;
561         u32 reg;
562         enum edac_type mode;
563         enum mem_type mtype;
564
565         pci_read_config_dword(pvt->pci_br, SAD_TARGET, &reg);
566         pvt->sbridge_dev->source_id = SOURCE_ID(reg);
567
568         pci_read_config_dword(pvt->pci_br, SAD_CONTROL, &reg);
569         pvt->sbridge_dev->node_id = NODE_ID(reg);
570         debugf0("mc#%d: Node ID: %d, source ID: %d\n",
571                 pvt->sbridge_dev->mc,
572                 pvt->sbridge_dev->node_id,
573                 pvt->sbridge_dev->source_id);
574
575         pci_read_config_dword(pvt->pci_ras, RASENABLES, &reg);
576         if (IS_MIRROR_ENABLED(reg)) {
577                 debugf0("Memory mirror is enabled\n");
578                 pvt->is_mirrored = true;
579         } else {
580                 debugf0("Memory mirror is disabled\n");
581                 pvt->is_mirrored = false;
582         }
583
584         pci_read_config_dword(pvt->pci_ta, MCMTR, &pvt->info.mcmtr);
585         if (IS_LOCKSTEP_ENABLED(pvt->info.mcmtr)) {
586                 debugf0("Lockstep is enabled\n");
587                 mode = EDAC_S8ECD8ED;
588                 pvt->is_lockstep = true;
589         } else {
590                 debugf0("Lockstep is disabled\n");
591                 mode = EDAC_S4ECD4ED;
592                 pvt->is_lockstep = false;
593         }
594         if (IS_CLOSE_PG(pvt->info.mcmtr)) {
595                 debugf0("address map is on closed page mode\n");
596                 pvt->is_close_pg = true;
597         } else {
598                 debugf0("address map is on open page mode\n");
599                 pvt->is_close_pg = false;
600         }
601
602         pci_read_config_dword(pvt->pci_ta, RANK_CFG_A, &reg);
603         if (IS_RDIMM_ENABLED(reg)) {
604                 /* FIXME: Can also be LRDIMM */
605                 debugf0("Memory is registered\n");
606                 mtype = MEM_RDDR3;
607         } else {
608                 debugf0("Memory is unregistered\n");
609                 mtype = MEM_DDR3;
610         }
611
612         /* On all supported DDR3 DIMM types, there are 8 banks available */
613         banks = 8;
614
615         for (i = 0; i < NUM_CHANNELS; i++) {
616                 u32 mtr;
617
618                 for (j = 0; j < ARRAY_SIZE(mtr_regs); j++) {
619                         pci_read_config_dword(pvt->pci_tad[i],
620                                               mtr_regs[j], &mtr);
621                         debugf4("Channel #%d  MTR%d = %x\n", i, j, mtr);
622                         if (IS_DIMM_PRESENT(mtr)) {
623                                 pvt->channel[i].dimms++;
624
625                                 ranks = numrank(mtr);
626                                 rows = numrow(mtr);
627                                 cols = numcol(mtr);
628
629                                 /* DDR3 has 8 I/O banks */
630                                 size = ((u64)rows * cols * banks * ranks) >> (20 - 3);
631                                 npages = MiB_TO_PAGES(size);
632
633                                 debugf0("mc#%d: channel %d, dimm %d, %Ld Mb (%d pages) bank: %d, rank: %d, row: %#x, col: %#x\n",
634                                         pvt->sbridge_dev->mc, i, j,
635                                         size, npages,
636                                         banks, ranks, rows, cols);
637                                 csr = &mci->csrows[csrow];
638
639                                 csr->first_page = last_page;
640                                 csr->last_page = last_page + npages - 1;
641                                 csr->page_mask = 0UL;   /* Unused */
642                                 csr->nr_pages = npages;
643                                 csr->grain = 32;
644                                 csr->csrow_idx = csrow;
645                                 csr->dtype = (banks == 8) ? DEV_X8 : DEV_X4;
646                                 csr->ce_count = 0;
647                                 csr->ue_count = 0;
648                                 csr->mtype = mtype;
649                                 csr->edac_mode = mode;
650                                 csr->nr_channels = 1;
651                                 csr->channels[0].chan_idx = i;
652                                 csr->channels[0].ce_count = 0;
653                                 pvt->csrow_map[i][j] = csrow;
654                                 snprintf(csr->channels[0].label,
655                                          sizeof(csr->channels[0].label),
656                                          "CPU_SrcID#%u_Channel#%u_DIMM#%u",
657                                          pvt->sbridge_dev->source_id, i, j);
658                                 last_page += npages;
659                                 csrow++;
660                         }
661                 }
662         }
663
664         return 0;
665 }
666
667 static void get_memory_layout(const struct mem_ctl_info *mci)
668 {
669         struct sbridge_pvt *pvt = mci->pvt_info;
670         int i, j, k, n_sads, n_tads, sad_interl;
671         u32 reg;
672         u64 limit, prv = 0;
673         u64 tmp_mb;
674         u32 rir_way;
675
676         /*
677          * Step 1) Get TOLM/TOHM ranges
678          */
679
680         /* Address range is 32:28 */
681         pci_read_config_dword(pvt->pci_sad1, TOLM,
682                               &reg);
683         pvt->tolm = GET_TOLM(reg);
684         tmp_mb = (1 + pvt->tolm) >> 20;
685
686         debugf0("TOLM: %Lu.%03Lu GB (0x%016Lx)\n",
687                 tmp_mb / 1000, tmp_mb % 1000, (u64)pvt->tolm);
688
689         /* Address range is already 45:25 */
690         pci_read_config_dword(pvt->pci_sad1, TOHM,
691                               &reg);
692         pvt->tohm = GET_TOHM(reg);
693         tmp_mb = (1 + pvt->tohm) >> 20;
694
695         debugf0("TOHM: %Lu.%03Lu GB (0x%016Lx)",
696                 tmp_mb / 1000, tmp_mb % 1000, (u64)pvt->tohm);
697
698         /*
699          * Step 2) Get SAD range and SAD Interleave list
700          * TAD registers contain the interleave wayness. However, it
701          * seems simpler to just discover it indirectly, with the
702          * algorithm bellow.
703          */
704         prv = 0;
705         for (n_sads = 0; n_sads < MAX_SAD; n_sads++) {
706                 /* SAD_LIMIT Address range is 45:26 */
707                 pci_read_config_dword(pvt->pci_sad0, dram_rule[n_sads],
708                                       &reg);
709                 limit = SAD_LIMIT(reg);
710
711                 if (!DRAM_RULE_ENABLE(reg))
712                         continue;
713
714                 if (limit <= prv)
715                         break;
716
717                 tmp_mb = (limit + 1) >> 20;
718                 debugf0("SAD#%d %s up to %Lu.%03Lu GB (0x%016Lx) %s reg=0x%08x\n",
719                         n_sads,
720                         get_dram_attr(reg),
721                         tmp_mb / 1000, tmp_mb % 1000,
722                         ((u64)tmp_mb) << 20L,
723                         INTERLEAVE_MODE(reg) ? "Interleave: 8:6" : "Interleave: [8:6]XOR[18:16]",
724                         reg);
725                 prv = limit;
726
727                 pci_read_config_dword(pvt->pci_sad0, interleave_list[n_sads],
728                                       &reg);
729                 sad_interl = sad_pkg(reg, 0);
730                 for (j = 0; j < 8; j++) {
731                         if (j > 0 && sad_interl == sad_pkg(reg, j))
732                                 break;
733
734                         debugf0("SAD#%d, interleave #%d: %d\n",
735                         n_sads, j, sad_pkg(reg, j));
736                 }
737         }
738
739         /*
740          * Step 3) Get TAD range
741          */
742         prv = 0;
743         for (n_tads = 0; n_tads < MAX_TAD; n_tads++) {
744                 pci_read_config_dword(pvt->pci_ha0, tad_dram_rule[n_tads],
745                                       &reg);
746                 limit = TAD_LIMIT(reg);
747                 if (limit <= prv)
748                         break;
749                 tmp_mb = (limit + 1) >> 20;
750
751                 debugf0("TAD#%d: up to %Lu.%03Lu GB (0x%016Lx), socket interleave %d, memory interleave %d, TGT: %d, %d, %d, %d, reg=0x%08x\n",
752                         n_tads, tmp_mb / 1000, tmp_mb % 1000,
753                         ((u64)tmp_mb) << 20L,
754                         (u32)TAD_SOCK(reg),
755                         (u32)TAD_CH(reg),
756                         (u32)TAD_TGT0(reg),
757                         (u32)TAD_TGT1(reg),
758                         (u32)TAD_TGT2(reg),
759                         (u32)TAD_TGT3(reg),
760                         reg);
761                 prv = tmp_mb;
762         }
763
764         /*
765          * Step 4) Get TAD offsets, per each channel
766          */
767         for (i = 0; i < NUM_CHANNELS; i++) {
768                 if (!pvt->channel[i].dimms)
769                         continue;
770                 for (j = 0; j < n_tads; j++) {
771                         pci_read_config_dword(pvt->pci_tad[i],
772                                               tad_ch_nilv_offset[j],
773                                               &reg);
774                         tmp_mb = TAD_OFFSET(reg) >> 20;
775                         debugf0("TAD CH#%d, offset #%d: %Lu.%03Lu GB (0x%016Lx), reg=0x%08x\n",
776                                 i, j,
777                                 tmp_mb / 1000, tmp_mb % 1000,
778                                 ((u64)tmp_mb) << 20L,
779                                 reg);
780                 }
781         }
782
783         /*
784          * Step 6) Get RIR Wayness/Limit, per each channel
785          */
786         for (i = 0; i < NUM_CHANNELS; i++) {
787                 if (!pvt->channel[i].dimms)
788                         continue;
789                 for (j = 0; j < MAX_RIR_RANGES; j++) {
790                         pci_read_config_dword(pvt->pci_tad[i],
791                                               rir_way_limit[j],
792                                               &reg);
793
794                         if (!IS_RIR_VALID(reg))
795                                 continue;
796
797                         tmp_mb = RIR_LIMIT(reg) >> 20;
798                         rir_way = 1 << RIR_WAY(reg);
799                         debugf0("CH#%d RIR#%d, limit: %Lu.%03Lu GB (0x%016Lx), way: %d, reg=0x%08x\n",
800                                 i, j,
801                                 tmp_mb / 1000, tmp_mb % 1000,
802                                 ((u64)tmp_mb) << 20L,
803                                 rir_way,
804                                 reg);
805
806                         for (k = 0; k < rir_way; k++) {
807                                 pci_read_config_dword(pvt->pci_tad[i],
808                                                       rir_offset[j][k],
809                                                       &reg);
810                                 tmp_mb = RIR_OFFSET(reg) << 6;
811
812                                 debugf0("CH#%d RIR#%d INTL#%d, offset %Lu.%03Lu GB (0x%016Lx), tgt: %d, reg=0x%08x\n",
813                                         i, j, k,
814                                         tmp_mb / 1000, tmp_mb % 1000,
815                                         ((u64)tmp_mb) << 20L,
816                                         (u32)RIR_RNK_TGT(reg),
817                                         reg);
818                         }
819                 }
820         }
821 }
822
823 struct mem_ctl_info *get_mci_for_node_id(u8 node_id)
824 {
825         struct sbridge_dev *sbridge_dev;
826
827         list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) {
828                 if (sbridge_dev->node_id == node_id)
829                         return sbridge_dev->mci;
830         }
831         return NULL;
832 }
833
834 static int get_memory_error_data(struct mem_ctl_info *mci,
835                                  u64 addr,
836                                  u8 *socket,
837                                  long *channel_mask,
838                                  u8 *rank,
839                                  char *area_type)
840 {
841         struct mem_ctl_info     *new_mci;
842         struct sbridge_pvt *pvt = mci->pvt_info;
843         char                    msg[256];
844         int                     n_rir, n_sads, n_tads, sad_way, sck_xch;
845         int                     sad_interl, idx, base_ch;
846         int                     interleave_mode;
847         unsigned                sad_interleave[MAX_INTERLEAVE];
848         u32                     reg;
849         u8                      ch_way,sck_way;
850         u32                     tad_offset;
851         u32                     rir_way;
852         u64                     ch_addr, offset, limit, prv = 0;
853
854
855         /*
856          * Step 0) Check if the address is at special memory ranges
857          * The check bellow is probably enough to fill all cases where
858          * the error is not inside a memory, except for the legacy
859          * range (e. g. VGA addresses). It is unlikely, however, that the
860          * memory controller would generate an error on that range.
861          */
862         if ((addr > (u64) pvt->tolm) && (addr < (1L << 32))) {
863                 sprintf(msg, "Error at TOLM area, on addr 0x%08Lx", addr);
864                 edac_mc_handle_ce_no_info(mci, msg);
865                 return -EINVAL;
866         }
867         if (addr >= (u64)pvt->tohm) {
868                 sprintf(msg, "Error at MMIOH area, on addr 0x%016Lx", addr);
869                 edac_mc_handle_ce_no_info(mci, msg);
870                 return -EINVAL;
871         }
872
873         /*
874          * Step 1) Get socket
875          */
876         for (n_sads = 0; n_sads < MAX_SAD; n_sads++) {
877                 pci_read_config_dword(pvt->pci_sad0, dram_rule[n_sads],
878                                       &reg);
879
880                 if (!DRAM_RULE_ENABLE(reg))
881                         continue;
882
883                 limit = SAD_LIMIT(reg);
884                 if (limit <= prv) {
885                         sprintf(msg, "Can't discover the memory socket");
886                         edac_mc_handle_ce_no_info(mci, msg);
887                         return -EINVAL;
888                 }
889                 if  (addr <= limit)
890                         break;
891                 prv = limit;
892         }
893         if (n_sads == MAX_SAD) {
894                 sprintf(msg, "Can't discover the memory socket");
895                 edac_mc_handle_ce_no_info(mci, msg);
896                 return -EINVAL;
897         }
898         area_type = get_dram_attr(reg);
899         interleave_mode = INTERLEAVE_MODE(reg);
900
901         pci_read_config_dword(pvt->pci_sad0, interleave_list[n_sads],
902                               &reg);
903         sad_interl = sad_pkg(reg, 0);
904         for (sad_way = 0; sad_way < 8; sad_way++) {
905                 if (sad_way > 0 && sad_interl == sad_pkg(reg, sad_way))
906                         break;
907                 sad_interleave[sad_way] = sad_pkg(reg, sad_way);
908                 debugf0("SAD interleave #%d: %d\n",
909                         sad_way, sad_interleave[sad_way]);
910         }
911         debugf0("mc#%d: Error detected on SAD#%d: address 0x%016Lx < 0x%016Lx, Interleave [%d:6]%s\n",
912                 pvt->sbridge_dev->mc,
913                 n_sads,
914                 addr,
915                 limit,
916                 sad_way + 7,
917                 INTERLEAVE_MODE(reg) ? "" : "XOR[18:16]");
918         if (interleave_mode)
919                 idx = ((addr >> 6) ^ (addr >> 16)) & 7;
920         else
921                 idx = (addr >> 6) & 7;
922         switch (sad_way) {
923         case 1:
924                 idx = 0;
925                 break;
926         case 2:
927                 idx = idx & 1;
928                 break;
929         case 4:
930                 idx = idx & 3;
931                 break;
932         case 8:
933                 break;
934         default:
935                 sprintf(msg, "Can't discover socket interleave");
936                 edac_mc_handle_ce_no_info(mci, msg);
937                 return -EINVAL;
938         }
939         *socket = sad_interleave[idx];
940         debugf0("SAD interleave index: %d (wayness %d) = CPU socket %d\n",
941                 idx, sad_way, *socket);
942
943         /*
944          * Move to the proper node structure, in order to access the
945          * right PCI registers
946          */
947         new_mci = get_mci_for_node_id(*socket);
948         if (!new_mci) {
949                 sprintf(msg, "Struct for socket #%u wasn't initialized",
950                         *socket);
951                 edac_mc_handle_ce_no_info(mci, msg);
952                 return -EINVAL;
953         }
954         mci = new_mci;
955         pvt = mci->pvt_info;
956
957         /*
958          * Step 2) Get memory channel
959          */
960         prv = 0;
961         for (n_tads = 0; n_tads < MAX_TAD; n_tads++) {
962                 pci_read_config_dword(pvt->pci_ha0, tad_dram_rule[n_tads],
963                                       &reg);
964                 limit = TAD_LIMIT(reg);
965                 if (limit <= prv) {
966                         sprintf(msg, "Can't discover the memory channel");
967                         edac_mc_handle_ce_no_info(mci, msg);
968                         return -EINVAL;
969                 }
970                 if  (addr <= limit)
971                         break;
972                 prv = limit;
973         }
974         ch_way = TAD_CH(reg) + 1;
975         sck_way = TAD_SOCK(reg) + 1;
976         /*
977          * FIXME: Is it right to always use channel 0 for offsets?
978          */
979         pci_read_config_dword(pvt->pci_tad[0],
980                                 tad_ch_nilv_offset[n_tads],
981                                 &tad_offset);
982
983         if (ch_way == 3)
984                 idx = addr >> 6;
985         else
986                 idx = addr >> (6 + sck_way);
987         idx = idx % ch_way;
988
989         /*
990          * FIXME: Shouldn't we use CHN_IDX_OFFSET() here, when ch_way == 3 ???
991          */
992         switch (idx) {
993         case 0:
994                 base_ch = TAD_TGT0(reg);
995                 break;
996         case 1:
997                 base_ch = TAD_TGT1(reg);
998                 break;
999         case 2:
1000                 base_ch = TAD_TGT2(reg);
1001                 break;
1002         case 3:
1003                 base_ch = TAD_TGT3(reg);
1004                 break;
1005         default:
1006                 sprintf(msg, "Can't discover the TAD target");
1007                 edac_mc_handle_ce_no_info(mci, msg);
1008                 return -EINVAL;
1009         }
1010         *channel_mask = 1 << base_ch;
1011
1012         if (pvt->is_mirrored) {
1013                 *channel_mask |= 1 << ((base_ch + 2) % 4);
1014                 switch(ch_way) {
1015                 case 2:
1016                 case 4:
1017                         sck_xch = 1 << sck_way * (ch_way >> 1);
1018                         break;
1019                 default:
1020                         sprintf(msg, "Invalid mirror set. Can't decode addr");
1021                         edac_mc_handle_ce_no_info(mci, msg);
1022                         return -EINVAL;
1023                 }
1024         } else
1025                 sck_xch = (1 << sck_way) * ch_way;
1026
1027         if (pvt->is_lockstep)
1028                 *channel_mask |= 1 << ((base_ch + 1) % 4);
1029
1030         offset = TAD_OFFSET(tad_offset);
1031
1032         debugf0("TAD#%d: address 0x%016Lx < 0x%016Lx, socket interleave %d, channel interleave %d (offset 0x%08Lx), index %d, base ch: %d, ch mask: 0x%02lx\n",
1033                 n_tads,
1034                 addr,
1035                 limit,
1036                 (u32)TAD_SOCK(reg),
1037                 ch_way,
1038                 offset,
1039                 idx,
1040                 base_ch,
1041                 *channel_mask);
1042
1043         /* Calculate channel address */
1044         /* Remove the TAD offset */
1045
1046         if (offset > addr) {
1047                 sprintf(msg, "Can't calculate ch addr: TAD offset 0x%08Lx is too high for addr 0x%08Lx!",
1048                         offset, addr);
1049                 edac_mc_handle_ce_no_info(mci, msg);
1050                 return -EINVAL;
1051         }
1052         addr -= offset;
1053         /* Store the low bits [0:6] of the addr */
1054         ch_addr = addr & 0x7f;
1055         /* Remove socket wayness and remove 6 bits */
1056         addr >>= 6;
1057         addr /= sck_xch;
1058 #if 0
1059         /* Divide by channel way */
1060         addr = addr / ch_way;
1061 #endif
1062         /* Recover the last 6 bits */
1063         ch_addr |= addr << 6;
1064
1065         /*
1066          * Step 3) Decode rank
1067          */
1068         for (n_rir = 0; n_rir < MAX_RIR_RANGES; n_rir++) {
1069                 pci_read_config_dword(pvt->pci_tad[base_ch],
1070                                       rir_way_limit[n_rir],
1071                                       &reg);
1072
1073                 if (!IS_RIR_VALID(reg))
1074                         continue;
1075
1076                 limit = RIR_LIMIT(reg);
1077
1078                 debugf0("RIR#%d, limit: %Lu.%03Lu GB (0x%016Lx), way: %d\n",
1079                         n_rir,
1080                         (limit >> 20) / 1000, (limit >> 20) % 1000,
1081                         limit,
1082                         1 << RIR_WAY(reg));
1083                 if  (ch_addr <= limit)
1084                         break;
1085         }
1086         if (n_rir == MAX_RIR_RANGES) {
1087                 sprintf(msg, "Can't discover the memory rank for ch addr 0x%08Lx",
1088                         ch_addr);
1089                 edac_mc_handle_ce_no_info(mci, msg);
1090                 return -EINVAL;
1091         }
1092         rir_way = RIR_WAY(reg);
1093         if (pvt->is_close_pg)
1094                 idx = (ch_addr >> 6);
1095         else
1096                 idx = (ch_addr >> 13);  /* FIXME: Datasheet says to shift by 15 */
1097         idx %= 1 << rir_way;
1098
1099         pci_read_config_dword(pvt->pci_tad[base_ch],
1100                               rir_offset[n_rir][idx],
1101                               &reg);
1102         *rank = RIR_RNK_TGT(reg);
1103
1104         debugf0("RIR#%d: channel address 0x%08Lx < 0x%08Lx, RIR interleave %d, index %d\n",
1105                 n_rir,
1106                 ch_addr,
1107                 limit,
1108                 rir_way,
1109                 idx);
1110
1111         return 0;
1112 }
1113
1114 /****************************************************************************
1115         Device initialization routines: put/get, init/exit
1116  ****************************************************************************/
1117
1118 /*
1119  *      sbridge_put_all_devices 'put' all the devices that we have
1120  *                              reserved via 'get'
1121  */
1122 static void sbridge_put_devices(struct sbridge_dev *sbridge_dev)
1123 {
1124         int i;
1125
1126         debugf0(__FILE__ ": %s()\n", __func__);
1127         for (i = 0; i < sbridge_dev->n_devs; i++) {
1128                 struct pci_dev *pdev = sbridge_dev->pdev[i];
1129                 if (!pdev)
1130                         continue;
1131                 debugf0("Removing dev %02x:%02x.%d\n",
1132                         pdev->bus->number,
1133                         PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
1134                 pci_dev_put(pdev);
1135         }
1136 }
1137
1138 static void sbridge_put_all_devices(void)
1139 {
1140         struct sbridge_dev *sbridge_dev, *tmp;
1141
1142         list_for_each_entry_safe(sbridge_dev, tmp, &sbridge_edac_list, list) {
1143                 sbridge_put_devices(sbridge_dev);
1144                 free_sbridge_dev(sbridge_dev);
1145         }
1146 }
1147
1148 /*
1149  *      sbridge_get_all_devices Find and perform 'get' operation on the MCH's
1150  *                      device/functions we want to reference for this driver
1151  *
1152  *                      Need to 'get' device 16 func 1 and func 2
1153  */
1154 static int sbridge_get_onedevice(struct pci_dev **prev,
1155                                  u8 *num_mc,
1156                                  const struct pci_id_table *table,
1157                                  const unsigned devno)
1158 {
1159         struct sbridge_dev *sbridge_dev;
1160         const struct pci_id_descr *dev_descr = &table->descr[devno];
1161
1162         struct pci_dev *pdev = NULL;
1163         u8 bus = 0;
1164
1165         sbridge_printk(KERN_INFO,
1166                 "Seeking for: dev %02x.%d PCI ID %04x:%04x\n",
1167                 dev_descr->dev, dev_descr->func,
1168                 PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
1169
1170         pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
1171                               dev_descr->dev_id, *prev);
1172
1173         if (!pdev) {
1174                 if (*prev) {
1175                         *prev = pdev;
1176                         return 0;
1177                 }
1178
1179                 if (dev_descr->optional)
1180                         return 0;
1181
1182                 if (devno == 0)
1183                         return -ENODEV;
1184
1185                 sbridge_printk(KERN_INFO,
1186                         "Device not found: dev %02x.%d PCI ID %04x:%04x\n",
1187                         dev_descr->dev, dev_descr->func,
1188                         PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
1189
1190                 /* End of list, leave */
1191                 return -ENODEV;
1192         }
1193         bus = pdev->bus->number;
1194
1195         sbridge_dev = get_sbridge_dev(bus);
1196         if (!sbridge_dev) {
1197                 sbridge_dev = alloc_sbridge_dev(bus, table);
1198                 if (!sbridge_dev) {
1199                         pci_dev_put(pdev);
1200                         return -ENOMEM;
1201                 }
1202                 (*num_mc)++;
1203         }
1204
1205         if (sbridge_dev->pdev[devno]) {
1206                 sbridge_printk(KERN_ERR,
1207                         "Duplicated device for "
1208                         "dev %02x:%d.%d PCI ID %04x:%04x\n",
1209                         bus, dev_descr->dev, dev_descr->func,
1210                         PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
1211                 pci_dev_put(pdev);
1212                 return -ENODEV;
1213         }
1214
1215         sbridge_dev->pdev[devno] = pdev;
1216
1217         /* Sanity check */
1218         if (unlikely(PCI_SLOT(pdev->devfn) != dev_descr->dev ||
1219                         PCI_FUNC(pdev->devfn) != dev_descr->func)) {
1220                 sbridge_printk(KERN_ERR,
1221                         "Device PCI ID %04x:%04x "
1222                         "has dev %02x:%d.%d instead of dev %02x:%02x.%d\n",
1223                         PCI_VENDOR_ID_INTEL, dev_descr->dev_id,
1224                         bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
1225                         bus, dev_descr->dev, dev_descr->func);
1226                 return -ENODEV;
1227         }
1228
1229         /* Be sure that the device is enabled */
1230         if (unlikely(pci_enable_device(pdev) < 0)) {
1231                 sbridge_printk(KERN_ERR,
1232                         "Couldn't enable "
1233                         "dev %02x:%d.%d PCI ID %04x:%04x\n",
1234                         bus, dev_descr->dev, dev_descr->func,
1235                         PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
1236                 return -ENODEV;
1237         }
1238
1239         debugf0("Detected dev %02x:%d.%d PCI ID %04x:%04x\n",
1240                 bus, dev_descr->dev,
1241                 dev_descr->func,
1242                 PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
1243
1244         /*
1245          * As stated on drivers/pci/search.c, the reference count for
1246          * @from is always decremented if it is not %NULL. So, as we need
1247          * to get all devices up to null, we need to do a get for the device
1248          */
1249         pci_dev_get(pdev);
1250
1251         *prev = pdev;
1252
1253         return 0;
1254 }
1255
1256 static int sbridge_get_all_devices(u8 *num_mc)
1257 {
1258         int i, rc;
1259         struct pci_dev *pdev = NULL;
1260         const struct pci_id_table *table = pci_dev_descr_sbridge_table;
1261
1262         while (table && table->descr) {
1263                 for (i = 0; i < table->n_devs; i++) {
1264                         pdev = NULL;
1265                         do {
1266                                 rc = sbridge_get_onedevice(&pdev, num_mc,
1267                                                            table, i);
1268                                 if (rc < 0) {
1269                                         if (i == 0) {
1270                                                 i = table->n_devs;
1271                                                 break;
1272                                         }
1273                                         sbridge_put_all_devices();
1274                                         return -ENODEV;
1275                                 }
1276                         } while (pdev);
1277                 }
1278                 table++;
1279         }
1280
1281         return 0;
1282 }
1283
1284 static int mci_bind_devs(struct mem_ctl_info *mci,
1285                          struct sbridge_dev *sbridge_dev)
1286 {
1287         struct sbridge_pvt *pvt = mci->pvt_info;
1288         struct pci_dev *pdev;
1289         int i, func, slot;
1290
1291         for (i = 0; i < sbridge_dev->n_devs; i++) {
1292                 pdev = sbridge_dev->pdev[i];
1293                 if (!pdev)
1294                         continue;
1295                 slot = PCI_SLOT(pdev->devfn);
1296                 func = PCI_FUNC(pdev->devfn);
1297                 switch (slot) {
1298                 case 12:
1299                         switch (func) {
1300                         case 6:
1301                                 pvt->pci_sad0 = pdev;
1302                                 break;
1303                         case 7:
1304                                 pvt->pci_sad1 = pdev;
1305                                 break;
1306                         default:
1307                                 goto error;
1308                         }
1309                         break;
1310                 case 13:
1311                         switch (func) {
1312                         case 6:
1313                                 pvt->pci_br = pdev;
1314                                 break;
1315                         default:
1316                                 goto error;
1317                         }
1318                         break;
1319                 case 14:
1320                         switch (func) {
1321                         case 0:
1322                                 pvt->pci_ha0 = pdev;
1323                                 break;
1324                         default:
1325                                 goto error;
1326                         }
1327                         break;
1328                 case 15:
1329                         switch (func) {
1330                         case 0:
1331                                 pvt->pci_ta = pdev;
1332                                 break;
1333                         case 1:
1334                                 pvt->pci_ras = pdev;
1335                                 break;
1336                         case 2:
1337                         case 3:
1338                         case 4:
1339                         case 5:
1340                                 pvt->pci_tad[func - 2] = pdev;
1341                                 break;
1342                         default:
1343                                 goto error;
1344                         }
1345                         break;
1346                 case 17:
1347                         switch (func) {
1348                         case 0:
1349                                 pvt->pci_ddrio = pdev;
1350                                 break;
1351                         default:
1352                                 goto error;
1353                         }
1354                         break;
1355                 default:
1356                         goto error;
1357                 }
1358
1359                 debugf0("Associated PCI %02x.%02d.%d with dev = %p\n",
1360                         sbridge_dev->bus,
1361                         PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
1362                         pdev);
1363         }
1364
1365         /* Check if everything were registered */
1366         if (!pvt->pci_sad0 || !pvt->pci_sad1 || !pvt->pci_ha0 ||
1367             !pvt-> pci_tad || !pvt->pci_ras  || !pvt->pci_ta ||
1368             !pvt->pci_ddrio)
1369                 goto enodev;
1370
1371         for (i = 0; i < NUM_CHANNELS; i++) {
1372                 if (!pvt->pci_tad[i])
1373                         goto enodev;
1374         }
1375         return 0;
1376
1377 enodev:
1378         sbridge_printk(KERN_ERR, "Some needed devices are missing\n");
1379         return -ENODEV;
1380
1381 error:
1382         sbridge_printk(KERN_ERR, "Device %d, function %d "
1383                       "is out of the expected range\n",
1384                       slot, func);
1385         return -EINVAL;
1386 }
1387
1388 /****************************************************************************
1389                         Error check routines
1390  ****************************************************************************/
1391
1392 /*
1393  * While Sandy Bridge has error count registers, SMI BIOS read values from
1394  * and resets the counters. So, they are not reliable for the OS to read
1395  * from them. So, we have no option but to just trust on whatever MCE is
1396  * telling us about the errors.
1397  */
1398 static void sbridge_mce_output_error(struct mem_ctl_info *mci,
1399                                     const struct mce *m)
1400 {
1401         struct mem_ctl_info *new_mci;
1402         struct sbridge_pvt *pvt = mci->pvt_info;
1403         char *type, *optype, *msg, *recoverable_msg;
1404         bool ripv = GET_BITFIELD(m->mcgstatus, 0, 0);
1405         bool overflow = GET_BITFIELD(m->status, 62, 62);
1406         bool uncorrected_error = GET_BITFIELD(m->status, 61, 61);
1407         bool recoverable = GET_BITFIELD(m->status, 56, 56);
1408         u32 core_err_cnt = GET_BITFIELD(m->status, 38, 52);
1409         u32 mscod = GET_BITFIELD(m->status, 16, 31);
1410         u32 errcode = GET_BITFIELD(m->status, 0, 15);
1411         u32 channel = GET_BITFIELD(m->status, 0, 3);
1412         u32 optypenum = GET_BITFIELD(m->status, 4, 6);
1413         long channel_mask, first_channel;
1414         u8  rank, socket;
1415         int csrow, rc, dimm;
1416         char *area_type = "Unknown";
1417
1418         if (ripv)
1419                 type = "NON_FATAL";
1420         else
1421                 type = "FATAL";
1422
1423         /*
1424          * According with Table 15-9 of the Intel Archictecture spec vol 3A,
1425          * memory errors should fit in this mask:
1426          *      000f 0000 1mmm cccc (binary)
1427          * where:
1428          *      f = Correction Report Filtering Bit. If 1, subsequent errors
1429          *          won't be shown
1430          *      mmm = error type
1431          *      cccc = channel
1432          * If the mask doesn't match, report an error to the parsing logic
1433          */
1434         if (! ((errcode & 0xef80) == 0x80)) {
1435                 optype = "Can't parse: it is not a mem";
1436         } else {
1437                 switch (optypenum) {
1438                 case 0:
1439                         optype = "generic undef request";
1440                         break;
1441                 case 1:
1442                         optype = "memory read";
1443                         break;
1444                 case 2:
1445                         optype = "memory write";
1446                         break;
1447                 case 3:
1448                         optype = "addr/cmd";
1449                         break;
1450                 case 4:
1451                         optype = "memory scrubbing";
1452                         break;
1453                 default:
1454                         optype = "reserved";
1455                         break;
1456                 }
1457         }
1458
1459         rc = get_memory_error_data(mci, m->addr, &socket,
1460                                    &channel_mask, &rank, area_type);
1461         if (rc < 0)
1462                 return;
1463         new_mci = get_mci_for_node_id(socket);
1464         if (!new_mci) {
1465                 edac_mc_handle_ce_no_info(mci, "Error: socket got corrupted!");
1466                 return;
1467         }
1468         mci = new_mci;
1469         pvt = mci->pvt_info;
1470
1471         first_channel = find_first_bit(&channel_mask, NUM_CHANNELS);
1472
1473         if (rank < 4)
1474                 dimm = 0;
1475         else if (rank < 8)
1476                 dimm = 1;
1477         else
1478                 dimm = 2;
1479
1480         csrow = pvt->csrow_map[first_channel][dimm];
1481
1482         if (uncorrected_error && recoverable)
1483                 recoverable_msg = " recoverable";
1484         else
1485                 recoverable_msg = "";
1486
1487         /*
1488          * FIXME: What should we do with "channel" information on mcelog?
1489          * Probably, we can just discard it, as the channel information
1490          * comes from the get_memory_error_data() address decoding
1491          */
1492         msg = kasprintf(GFP_ATOMIC,
1493                         "%d %s error(s): %s on %s area %s%s: cpu=%d Err=%04x:%04x (ch=%d), "
1494                         "addr = 0x%08llx => socket=%d, Channel=%ld(mask=%ld), rank=%d\n",
1495                         core_err_cnt,
1496                         area_type,
1497                         optype,
1498                         type,
1499                         recoverable_msg,
1500                         overflow ? "OVERFLOW" : "",
1501                         m->cpu,
1502                         mscod, errcode,
1503                         channel,                /* 1111b means not specified */
1504                         (long long) m->addr,
1505                         socket,
1506                         first_channel,          /* This is the real channel on SB */
1507                         channel_mask,
1508                         rank);
1509
1510         debugf0("%s", msg);
1511
1512         /* Call the helper to output message */
1513         if (uncorrected_error)
1514                 edac_mc_handle_fbd_ue(mci, csrow, 0, 0, msg);
1515         else
1516                 edac_mc_handle_fbd_ce(mci, csrow, 0, msg);
1517
1518         kfree(msg);
1519 }
1520
1521 /*
1522  *      sbridge_check_error     Retrieve and process errors reported by the
1523  *                              hardware. Called by the Core module.
1524  */
1525 static void sbridge_check_error(struct mem_ctl_info *mci)
1526 {
1527         struct sbridge_pvt *pvt = mci->pvt_info;
1528         int i;
1529         unsigned count = 0;
1530         struct mce *m;
1531
1532         /*
1533          * MCE first step: Copy all mce errors into a temporary buffer
1534          * We use a double buffering here, to reduce the risk of
1535          * loosing an error.
1536          */
1537         smp_rmb();
1538         count = (pvt->mce_out + MCE_LOG_LEN - pvt->mce_in)
1539                 % MCE_LOG_LEN;
1540         if (!count)
1541                 return;
1542
1543         m = pvt->mce_outentry;
1544         if (pvt->mce_in + count > MCE_LOG_LEN) {
1545                 unsigned l = MCE_LOG_LEN - pvt->mce_in;
1546
1547                 memcpy(m, &pvt->mce_entry[pvt->mce_in], sizeof(*m) * l);
1548                 smp_wmb();
1549                 pvt->mce_in = 0;
1550                 count -= l;
1551                 m += l;
1552         }
1553         memcpy(m, &pvt->mce_entry[pvt->mce_in], sizeof(*m) * count);
1554         smp_wmb();
1555         pvt->mce_in += count;
1556
1557         smp_rmb();
1558         if (pvt->mce_overrun) {
1559                 sbridge_printk(KERN_ERR, "Lost %d memory errors\n",
1560                               pvt->mce_overrun);
1561                 smp_wmb();
1562                 pvt->mce_overrun = 0;
1563         }
1564
1565         /*
1566          * MCE second step: parse errors and display
1567          */
1568         for (i = 0; i < count; i++)
1569                 sbridge_mce_output_error(mci, &pvt->mce_outentry[i]);
1570 }
1571
1572 /*
1573  * sbridge_mce_check_error      Replicates mcelog routine to get errors
1574  *                              This routine simply queues mcelog errors, and
1575  *                              return. The error itself should be handled later
1576  *                              by sbridge_check_error.
1577  * WARNING: As this routine should be called at NMI time, extra care should
1578  * be taken to avoid deadlocks, and to be as fast as possible.
1579  */
1580 static int sbridge_mce_check_error(struct notifier_block *nb, unsigned long val,
1581                                    void *data)
1582 {
1583         struct mce *mce = (struct mce *)data;
1584         struct mem_ctl_info *mci;
1585         struct sbridge_pvt *pvt;
1586
1587         mci = get_mci_for_node_id(mce->socketid);
1588         if (!mci)
1589                 return NOTIFY_BAD;
1590         pvt = mci->pvt_info;
1591
1592         /*
1593          * Just let mcelog handle it if the error is
1594          * outside the memory controller. A memory error
1595          * is indicated by bit 7 = 1 and bits = 8-11,13-15 = 0.
1596          * bit 12 has an special meaning.
1597          */
1598         if ((mce->status & 0xefff) >> 7 != 1)
1599                 return NOTIFY_DONE;
1600
1601         printk("sbridge: HANDLING MCE MEMORY ERROR\n");
1602
1603         printk("CPU %d: Machine Check Exception: %Lx Bank %d: %016Lx\n",
1604                mce->extcpu, mce->mcgstatus, mce->bank, mce->status);
1605         printk("TSC %llx ", mce->tsc);
1606         printk("ADDR %llx ", mce->addr);
1607         printk("MISC %llx ", mce->misc);
1608
1609         printk("PROCESSOR %u:%x TIME %llu SOCKET %u APIC %x\n",
1610                 mce->cpuvendor, mce->cpuid, mce->time,
1611                 mce->socketid, mce->apicid);
1612
1613         /* Only handle if it is the right mc controller */
1614         if (cpu_data(mce->cpu).phys_proc_id != pvt->sbridge_dev->mc)
1615                 return NOTIFY_DONE;
1616
1617         smp_rmb();
1618         if ((pvt->mce_out + 1) % MCE_LOG_LEN == pvt->mce_in) {
1619                 smp_wmb();
1620                 pvt->mce_overrun++;
1621                 return NOTIFY_DONE;
1622         }
1623
1624         /* Copy memory error at the ringbuffer */
1625         memcpy(&pvt->mce_entry[pvt->mce_out], mce, sizeof(*mce));
1626         smp_wmb();
1627         pvt->mce_out = (pvt->mce_out + 1) % MCE_LOG_LEN;
1628
1629         /* Handle fatal errors immediately */
1630         if (mce->mcgstatus & 1)
1631                 sbridge_check_error(mci);
1632
1633         /* Advice mcelog that the error were handled */
1634         return NOTIFY_STOP;
1635 }
1636
1637 static struct notifier_block sbridge_mce_dec = {
1638         .notifier_call      = sbridge_mce_check_error,
1639 };
1640
1641 /****************************************************************************
1642                         EDAC register/unregister logic
1643  ****************************************************************************/
1644
1645 static void sbridge_unregister_mci(struct sbridge_dev *sbridge_dev)
1646 {
1647         struct mem_ctl_info *mci = sbridge_dev->mci;
1648         struct sbridge_pvt *pvt;
1649
1650         if (unlikely(!mci || !mci->pvt_info)) {
1651                 debugf0("MC: " __FILE__ ": %s(): dev = %p\n",
1652                         __func__, &sbridge_dev->pdev[0]->dev);
1653
1654                 sbridge_printk(KERN_ERR, "Couldn't find mci handler\n");
1655                 return;
1656         }
1657
1658         pvt = mci->pvt_info;
1659
1660         debugf0("MC: " __FILE__ ": %s(): mci = %p, dev = %p\n",
1661                 __func__, mci, &sbridge_dev->pdev[0]->dev);
1662
1663         /* Remove MC sysfs nodes */
1664         edac_mc_del_mc(mci->dev);
1665
1666         debugf1("%s: free mci struct\n", mci->ctl_name);
1667         kfree(mci->ctl_name);
1668         edac_mc_free(mci);
1669         sbridge_dev->mci = NULL;
1670 }
1671
1672 static int sbridge_register_mci(struct sbridge_dev *sbridge_dev)
1673 {
1674         struct mem_ctl_info *mci;
1675         struct sbridge_pvt *pvt;
1676         int rc, channels, csrows;
1677
1678         /* Check the number of active and not disabled channels */
1679         rc = sbridge_get_active_channels(sbridge_dev->bus, &channels, &csrows);
1680         if (unlikely(rc < 0))
1681                 return rc;
1682
1683         /* allocate a new MC control structure */
1684         mci = edac_mc_alloc(sizeof(*pvt), csrows, channels, sbridge_dev->mc);
1685         if (unlikely(!mci))
1686                 return -ENOMEM;
1687
1688         debugf0("MC: " __FILE__ ": %s(): mci = %p, dev = %p\n",
1689                 __func__, mci, &sbridge_dev->pdev[0]->dev);
1690
1691         pvt = mci->pvt_info;
1692         memset(pvt, 0, sizeof(*pvt));
1693
1694         /* Associate sbridge_dev and mci for future usage */
1695         pvt->sbridge_dev = sbridge_dev;
1696         sbridge_dev->mci = mci;
1697
1698         mci->mtype_cap = MEM_FLAG_DDR3;
1699         mci->edac_ctl_cap = EDAC_FLAG_NONE;
1700         mci->edac_cap = EDAC_FLAG_NONE;
1701         mci->mod_name = "sbridge_edac.c";
1702         mci->mod_ver = SBRIDGE_REVISION;
1703         mci->ctl_name = kasprintf(GFP_KERNEL, "Sandy Bridge Socket#%d", mci->mc_idx);
1704         mci->dev_name = pci_name(sbridge_dev->pdev[0]);
1705         mci->ctl_page_to_phys = NULL;
1706
1707         /* Set the function pointer to an actual operation function */
1708         mci->edac_check = sbridge_check_error;
1709
1710         /* Store pci devices at mci for faster access */
1711         rc = mci_bind_devs(mci, sbridge_dev);
1712         if (unlikely(rc < 0))
1713                 goto fail0;
1714
1715         /* Get dimm basic config and the memory layout */
1716         get_dimm_config(mci);
1717         get_memory_layout(mci);
1718
1719         /* record ptr to the generic device */
1720         mci->dev = &sbridge_dev->pdev[0]->dev;
1721
1722         /* add this new MC control structure to EDAC's list of MCs */
1723         if (unlikely(edac_mc_add_mc(mci))) {
1724                 debugf0("MC: " __FILE__
1725                         ": %s(): failed edac_mc_add_mc()\n", __func__);
1726                 rc = -EINVAL;
1727                 goto fail0;
1728         }
1729
1730         return 0;
1731
1732 fail0:
1733         kfree(mci->ctl_name);
1734         edac_mc_free(mci);
1735         sbridge_dev->mci = NULL;
1736         return rc;
1737 }
1738
1739 /*
1740  *      sbridge_probe   Probe for ONE instance of device to see if it is
1741  *                      present.
1742  *      return:
1743  *              0 for FOUND a device
1744  *              < 0 for error code
1745  */
1746
1747 static int __devinit sbridge_probe(struct pci_dev *pdev,
1748                                   const struct pci_device_id *id)
1749 {
1750         int rc;
1751         u8 mc, num_mc = 0;
1752         struct sbridge_dev *sbridge_dev;
1753
1754         /* get the pci devices we want to reserve for our use */
1755         mutex_lock(&sbridge_edac_lock);
1756
1757         /*
1758          * All memory controllers are allocated at the first pass.
1759          */
1760         if (unlikely(probed >= 1)) {
1761                 mutex_unlock(&sbridge_edac_lock);
1762                 return -ENODEV;
1763         }
1764         probed++;
1765
1766         rc = sbridge_get_all_devices(&num_mc);
1767         if (unlikely(rc < 0))
1768                 goto fail0;
1769         mc = 0;
1770
1771         list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) {
1772                 debugf0("Registering MC#%d (%d of %d)\n", mc, mc + 1, num_mc);
1773                 sbridge_dev->mc = mc++;
1774                 rc = sbridge_register_mci(sbridge_dev);
1775                 if (unlikely(rc < 0))
1776                         goto fail1;
1777         }
1778
1779         sbridge_printk(KERN_INFO, "Driver loaded.\n");
1780
1781         mutex_unlock(&sbridge_edac_lock);
1782         return 0;
1783
1784 fail1:
1785         list_for_each_entry(sbridge_dev, &sbridge_edac_list, list)
1786                 sbridge_unregister_mci(sbridge_dev);
1787
1788         sbridge_put_all_devices();
1789 fail0:
1790         mutex_unlock(&sbridge_edac_lock);
1791         return rc;
1792 }
1793
1794 /*
1795  *      sbridge_remove  destructor for one instance of device
1796  *
1797  */
1798 static void __devexit sbridge_remove(struct pci_dev *pdev)
1799 {
1800         struct sbridge_dev *sbridge_dev;
1801
1802         debugf0(__FILE__ ": %s()\n", __func__);
1803
1804         /*
1805          * we have a trouble here: pdev value for removal will be wrong, since
1806          * it will point to the X58 register used to detect that the machine
1807          * is a Nehalem or upper design. However, due to the way several PCI
1808          * devices are grouped together to provide MC functionality, we need
1809          * to use a different method for releasing the devices
1810          */
1811
1812         mutex_lock(&sbridge_edac_lock);
1813
1814         if (unlikely(!probed)) {
1815                 mutex_unlock(&sbridge_edac_lock);
1816                 return;
1817         }
1818
1819         list_for_each_entry(sbridge_dev, &sbridge_edac_list, list)
1820                 sbridge_unregister_mci(sbridge_dev);
1821
1822         /* Release PCI resources */
1823         sbridge_put_all_devices();
1824
1825         probed--;
1826
1827         mutex_unlock(&sbridge_edac_lock);
1828 }
1829
1830 MODULE_DEVICE_TABLE(pci, sbridge_pci_tbl);
1831
1832 /*
1833  *      sbridge_driver  pci_driver structure for this module
1834  *
1835  */
1836 static struct pci_driver sbridge_driver = {
1837         .name     = "sbridge_edac",
1838         .probe    = sbridge_probe,
1839         .remove   = __devexit_p(sbridge_remove),
1840         .id_table = sbridge_pci_tbl,
1841 };
1842
1843 /*
1844  *      sbridge_init            Module entry function
1845  *                      Try to initialize this module for its devices
1846  */
1847 static int __init sbridge_init(void)
1848 {
1849         int pci_rc;
1850
1851         debugf2("MC: " __FILE__ ": %s()\n", __func__);
1852
1853         /* Ensure that the OPSTATE is set correctly for POLL or NMI */
1854         opstate_init();
1855
1856         pci_rc = pci_register_driver(&sbridge_driver);
1857
1858         if (pci_rc >= 0) {
1859                 atomic_notifier_chain_register(&x86_mce_decoder_chain, &sbridge_mce_dec);
1860                 return 0;
1861         }
1862
1863         sbridge_printk(KERN_ERR, "Failed to register device with error %d.\n",
1864                       pci_rc);
1865
1866         return pci_rc;
1867 }
1868
1869 /*
1870  *      sbridge_exit()  Module exit function
1871  *                      Unregister the driver
1872  */
1873 static void __exit sbridge_exit(void)
1874 {
1875         debugf2("MC: " __FILE__ ": %s()\n", __func__);
1876         pci_unregister_driver(&sbridge_driver);
1877         atomic_notifier_chain_unregister(&x86_mce_decoder_chain, &sbridge_mce_dec);
1878 }
1879
1880 module_init(sbridge_init);
1881 module_exit(sbridge_exit);
1882
1883 module_param(edac_op_state, int, 0444);
1884 MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
1885
1886 MODULE_LICENSE("GPL");
1887 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
1888 MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
1889 MODULE_DESCRIPTION("MC Driver for Intel Sandy Bridge memory controllers - "
1890                    SBRIDGE_REVISION);