2 * Intel 82975X Memory Controller kernel module
3 * (C) 2007 aCarLab (India) Pvt. Ltd. (http://acarlab.com)
4 * (C) 2007 jetzbroadband (http://jetzbroadband.com)
5 * This file may be distributed under the terms of the
6 * GNU General Public License.
9 * Copied from i82875p_edac.c source:
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/pci.h>
15 #include <linux/pci_ids.h>
16 #include <linux/edac.h>
17 #include "edac_module.h"
19 #define EDAC_MOD_STR "i82975x_edac"
21 #define i82975x_printk(level, fmt, arg...) \
22 edac_printk(level, "i82975x", fmt, ##arg)
24 #define i82975x_mc_printk(mci, level, fmt, arg...) \
25 edac_mc_chipset_printk(mci, level, "i82975x", fmt, ##arg)
27 #ifndef PCI_DEVICE_ID_INTEL_82975_0
28 #define PCI_DEVICE_ID_INTEL_82975_0 0x277c
29 #endif /* PCI_DEVICE_ID_INTEL_82975_0 */
31 #define I82975X_NR_DIMMS 8
32 #define I82975X_NR_CSROWS(nr_chans) (I82975X_NR_DIMMS / (nr_chans))
34 /* Intel 82975X register addresses - device 0 function 0 - DRAM Controller */
35 #define I82975X_EAP 0x58 /* Dram Error Address Pointer (32b)
37 * 31:7 128 byte cache-line address
42 #define I82975X_DERRSYN 0x5c /* Dram Error SYNdrome (8b)
44 * 7:0 DRAM ECC Syndrome
47 #define I82975X_DES 0x5d /* Dram ERRor DeSTination (8b)
48 * 0h: Processor Memory Reads
50 * More - See Page 65 of Intel DocSheet.
53 #define I82975X_ERRSTS 0xc8 /* Error Status Register (16b)
56 * 11 Thermal Sensor Event
58 * 9 non-DRAM lock error (ndlock)
61 * 1 ECC UE (multibit DRAM error)
62 * 0 ECC CE (singlebit DRAM error)
65 /* Error Reporting is supported by 3 mechanisms:
66 1. DMI SERR generation ( ERRCMD )
67 2. SMI DMI generation ( SMICMD )
68 3. SCI DMI generation ( SCICMD )
69 NOTE: Only ONE of the three must be enabled
71 #define I82975X_ERRCMD 0xca /* Error Command (16b)
74 * 11 Thermal Sensor Event
76 * 9 non-DRAM lock error (ndlock)
79 * 1 ECC UE (multibit DRAM error)
80 * 0 ECC CE (singlebit DRAM error)
83 #define I82975X_SMICMD 0xcc /* Error Command (16b)
86 * 1 ECC UE (multibit DRAM error)
87 * 0 ECC CE (singlebit DRAM error)
90 #define I82975X_SCICMD 0xce /* Error Command (16b)
93 * 1 ECC UE (multibit DRAM error)
94 * 0 ECC CE (singlebit DRAM error)
97 #define I82975X_XEAP 0xfc /* Extended Dram Error Address Pointer (8b)
100 * 0 Bit32 of the Dram Error Address
103 #define I82975X_MCHBAR 0x44 /*
105 * 31:14 Base Addr of 16K memory-mapped
106 * configuration space
108 * 0 mem-mapped config space enable
111 /* NOTE: Following addresses have to indexed using MCHBAR offset (44h, 32b) */
112 /* Intel 82975x memory mapped register space */
114 #define I82975X_DRB_SHIFT 25 /* fixed 32MiB grain */
116 #define I82975X_DRB 0x100 /* DRAM Row Boundary (8b x 8)
118 * 7 set to 1 in highest DRB of
119 * channel if 4GB in ch.
120 * 6:2 upper boundary of rank in
124 #define I82975X_DRB_CH0R0 0x100
125 #define I82975X_DRB_CH0R1 0x101
126 #define I82975X_DRB_CH0R2 0x102
127 #define I82975X_DRB_CH0R3 0x103
128 #define I82975X_DRB_CH1R0 0x180
129 #define I82975X_DRB_CH1R1 0x181
130 #define I82975X_DRB_CH1R2 0x182
131 #define I82975X_DRB_CH1R3 0x183
134 #define I82975X_DRA 0x108 /* DRAM Row Attribute (4b x 8)
135 * defines the PAGE SIZE to be used
138 * 6:4 row attr of odd rank, i.e. 1
140 * 2:0 row attr of even rank, i.e. 0
149 #define I82975X_DRA_CH0R01 0x108
150 #define I82975X_DRA_CH0R23 0x109
151 #define I82975X_DRA_CH1R01 0x188
152 #define I82975X_DRA_CH1R23 0x189
155 #define I82975X_BNKARC 0x10e /* Type of device in each rank - Bank Arch (16b)
158 * 7:6 Rank 3 architecture
159 * 5:4 Rank 2 architecture
160 * 3:2 Rank 1 architecture
161 * 1:0 Rank 0 architecture
166 #define I82975X_C0BNKARC 0x10e
167 #define I82975X_C1BNKARC 0x18e
171 #define I82975X_DRC 0x120 /* DRAM Controller Mode0 (32b)
175 * 28:11 reserved, according to Intel
176 * 22:21 number of channels
178 * seems to be ECC mode
179 * bits in 82975 in Asus
181 * 19:18 Data Integ Mode
182 * 00=none 01=ECC in 82875
187 * 1:0 DRAM type 10=Second Revision
189 * 00, 01, 11 reserved
191 #define I82975X_DRC_CH0M0 0x120
192 #define I82975X_DRC_CH1M0 0x1A0
195 #define I82975X_DRC_M1 0x124 /* DRAM Controller Mode1 (32b)
196 * 31 0=Standard Address Map
197 * 1=Enhanced Address Map
201 #define I82975X_DRC_CH0M1 0x124
202 #define I82975X_DRC_CH1M1 0x1A4
209 void __iomem
*mch_window
;
212 struct i82975x_dev_info
{
213 const char *ctl_name
;
216 struct i82975x_error_info
{
222 u8 chan
; /* the channel is bit 0 of EAP */
223 u8 xeap
; /* extended eap bit */
226 static const struct i82975x_dev_info i82975x_devs
[] = {
228 .ctl_name
= "i82975x"
232 static struct pci_dev
*mci_pdev
; /* init dev: in case that AGP code has
233 * already registered driver
236 static int i82975x_registered
= 1;
238 static void i82975x_get_error_info(struct mem_ctl_info
*mci
,
239 struct i82975x_error_info
*info
)
241 struct pci_dev
*pdev
;
243 pdev
= to_pci_dev(mci
->pdev
);
246 * This is a mess because there is no atomic way to read all the
247 * registers at once and the registers can transition from CE being
250 pci_read_config_word(pdev
, I82975X_ERRSTS
, &info
->errsts
);
251 pci_read_config_dword(pdev
, I82975X_EAP
, &info
->eap
);
252 pci_read_config_byte(pdev
, I82975X_XEAP
, &info
->xeap
);
253 pci_read_config_byte(pdev
, I82975X_DES
, &info
->des
);
254 pci_read_config_byte(pdev
, I82975X_DERRSYN
, &info
->derrsyn
);
255 pci_read_config_word(pdev
, I82975X_ERRSTS
, &info
->errsts2
);
257 pci_write_bits16(pdev
, I82975X_ERRSTS
, 0x0003, 0x0003);
260 * If the error is the same then we can for both reads then
261 * the first set of reads is valid. If there is a change then
262 * there is a CE no info and the second set of reads is valid
263 * and should be UE info.
265 if (!(info
->errsts2
& 0x0003))
268 if ((info
->errsts
^ info
->errsts2
) & 0x0003) {
269 pci_read_config_dword(pdev
, I82975X_EAP
, &info
->eap
);
270 pci_read_config_byte(pdev
, I82975X_XEAP
, &info
->xeap
);
271 pci_read_config_byte(pdev
, I82975X_DES
, &info
->des
);
272 pci_read_config_byte(pdev
, I82975X_DERRSYN
,
277 static int i82975x_process_error_info(struct mem_ctl_info
*mci
,
278 struct i82975x_error_info
*info
, int handle_errors
)
281 unsigned long offst
, page
;
283 if (!(info
->errsts2
& 0x0003))
289 if ((info
->errsts
^ info
->errsts2
) & 0x0003) {
290 edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED
, mci
, 1, 0, 0, 0,
291 -1, -1, -1, "UE overwrote CE", "");
292 info
->errsts
= info
->errsts2
;
295 page
= (unsigned long) info
->eap
;
299 page
>>= (PAGE_SHIFT
- 1);
300 row
= edac_mc_find_csrow_by_page(mci
, page
);
303 i82975x_mc_printk(mci
, KERN_ERR
, "error processing EAP:\n"
307 (info
->xeap
& 1) ? 1 : 0, info
->eap
, (unsigned int) page
);
310 chan
= (mci
->csrows
[row
]->nr_channels
== 1) ? 0 : info
->eap
& 1;
312 & ((1 << PAGE_SHIFT
) -
313 (1 << mci
->csrows
[row
]->channels
[chan
]->dimm
->grain
));
315 if (info
->errsts
& 0x0002)
316 edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED
, mci
, 1,
321 edac_mc_handle_error(HW_EVENT_ERR_CORRECTED
, mci
, 1,
322 page
, offst
, info
->derrsyn
,
323 row
, chan
? chan
: 0, -1,
329 static void i82975x_check(struct mem_ctl_info
*mci
)
331 struct i82975x_error_info info
;
333 edac_dbg(1, "MC%d\n", mci
->mc_idx
);
334 i82975x_get_error_info(mci
, &info
);
335 i82975x_process_error_info(mci
, &info
, 1);
338 /* Return 1 if dual channel mode is active. Else return 0. */
339 static int dual_channel_active(void __iomem
*mch_window
)
342 * We treat interleaved-symmetric configuration as dual-channel - EAP's
343 * bit-0 giving the channel of the error location.
345 * All other configurations are treated as single channel - the EAP's
346 * bit-0 will resolve ok in symmetric area of mixed
347 * (symmetric/asymmetric) configurations
353 for (dualch
= 1, row
= 0; dualch
&& (row
< 4); row
++) {
354 drb
[row
][0] = readb(mch_window
+ I82975X_DRB
+ row
);
355 drb
[row
][1] = readb(mch_window
+ I82975X_DRB
+ row
+ 0x80);
356 dualch
= dualch
&& (drb
[row
][0] == drb
[row
][1]);
361 static void i82975x_init_csrows(struct mem_ctl_info
*mci
,
362 struct pci_dev
*pdev
, void __iomem
*mch_window
)
364 struct csrow_info
*csrow
;
365 unsigned long last_cumul_size
;
367 u32 cumul_size
, nr_pages
;
369 struct dimm_info
*dimm
;
375 * The dram row boundary (DRB) reg values are boundary address
376 * for each DRAM row with a granularity of 32 or 64MB (single/dual
377 * channel operation). DRB regs are cumulative; therefore DRB7 will
378 * contain the total memory contained in all rows.
382 for (index
= 0; index
< mci
->nr_csrows
; index
++) {
383 csrow
= mci
->csrows
[index
];
385 value
= readb(mch_window
+ I82975X_DRB
+ index
+
386 ((index
>= 4) ? 0x80 : 0));
388 cumul_size
<<= (I82975X_DRB_SHIFT
- PAGE_SHIFT
);
390 * Adjust cumul_size w.r.t number of channels
393 if (csrow
->nr_channels
> 1)
395 edac_dbg(3, "(%d) cumul_size 0x%x\n", index
, cumul_size
);
397 nr_pages
= cumul_size
- last_cumul_size
;
402 * Initialise dram labels
404 * [0-7] for single-channel; i.e. csrow->nr_channels = 1
405 * [0-3] for dual-channel; i.e. csrow->nr_channels = 2
407 for (chan
= 0; chan
< csrow
->nr_channels
; chan
++) {
408 dimm
= mci
->csrows
[index
]->channels
[chan
]->dimm
;
410 dimm
->nr_pages
= nr_pages
/ csrow
->nr_channels
;
412 snprintf(csrow
->channels
[chan
]->dimm
->label
, EDAC_MC_LABEL_LEN
, "DIMM %c%d",
413 (chan
== 0) ? 'A' : 'B',
415 dimm
->grain
= 1 << 7; /* 128Byte cache-line resolution */
417 /* ECC is possible on i92975x ONLY with DEV_X8. */
418 dimm
->dtype
= DEV_X8
;
420 dimm
->mtype
= MEM_DDR2
; /* I82975x supports only DDR2 */
421 dimm
->edac_mode
= EDAC_SECDED
; /* only supported */
424 csrow
->first_page
= last_cumul_size
;
425 csrow
->last_page
= cumul_size
- 1;
426 last_cumul_size
= cumul_size
;
430 /* #define i82975x_DEBUG_IOMEM */
432 #ifdef i82975x_DEBUG_IOMEM
433 static void i82975x_print_dram_timings(void __iomem
*mch_window
)
436 * The register meanings are from Intel specs;
437 * (shows 13-5-5-5 for 800-DDR2)
438 * Asus P5W Bios reports 15-5-4-4
439 * What's your religion?
441 static const int caslats
[4] = { 5, 4, 3, 6 };
444 dtreg
[0] = readl(mch_window
+ 0x114);
445 dtreg
[1] = readl(mch_window
+ 0x194);
446 i82975x_printk(KERN_INFO
, "DRAM Timings : Ch0 Ch1\n"
447 " RAS Active Min = %d %d\n"
448 " CAS latency = %d %d\n"
449 " RAS to CAS = %d %d\n"
450 " RAS precharge = %d %d\n",
451 (dtreg
[0] >> 19 ) & 0x0f,
452 (dtreg
[1] >> 19) & 0x0f,
453 caslats
[(dtreg
[0] >> 8) & 0x03],
454 caslats
[(dtreg
[1] >> 8) & 0x03],
455 ((dtreg
[0] >> 4) & 0x07) + 2,
456 ((dtreg
[1] >> 4) & 0x07) + 2,
457 (dtreg
[0] & 0x07) + 2,
458 (dtreg
[1] & 0x07) + 2
464 static int i82975x_probe1(struct pci_dev
*pdev
, int dev_idx
)
467 struct mem_ctl_info
*mci
;
468 struct edac_mc_layer layers
[2];
469 struct i82975x_pvt
*pvt
;
470 void __iomem
*mch_window
;
473 struct i82975x_error_info discard
;
475 #ifdef i82975x_DEBUG_IOMEM
482 pci_read_config_dword(pdev
, I82975X_MCHBAR
, &mchbar
);
484 edac_dbg(3, "failed, MCHBAR disabled!\n");
487 mchbar
&= 0xffffc000; /* bits 31:14 used for 16K window */
488 mch_window
= ioremap_nocache(mchbar
, 0x1000);
490 edac_dbg(3, "error ioremapping MCHBAR!\n");
494 #ifdef i82975x_DEBUG_IOMEM
495 i82975x_printk(KERN_INFO
, "MCHBAR real = %0x, remapped = %p\n",
498 c0drb
[0] = readb(mch_window
+ I82975X_DRB_CH0R0
);
499 c0drb
[1] = readb(mch_window
+ I82975X_DRB_CH0R1
);
500 c0drb
[2] = readb(mch_window
+ I82975X_DRB_CH0R2
);
501 c0drb
[3] = readb(mch_window
+ I82975X_DRB_CH0R3
);
502 c1drb
[0] = readb(mch_window
+ I82975X_DRB_CH1R0
);
503 c1drb
[1] = readb(mch_window
+ I82975X_DRB_CH1R1
);
504 c1drb
[2] = readb(mch_window
+ I82975X_DRB_CH1R2
);
505 c1drb
[3] = readb(mch_window
+ I82975X_DRB_CH1R3
);
506 i82975x_printk(KERN_INFO
, "DRBCH0R0 = 0x%02x\n", c0drb
[0]);
507 i82975x_printk(KERN_INFO
, "DRBCH0R1 = 0x%02x\n", c0drb
[1]);
508 i82975x_printk(KERN_INFO
, "DRBCH0R2 = 0x%02x\n", c0drb
[2]);
509 i82975x_printk(KERN_INFO
, "DRBCH0R3 = 0x%02x\n", c0drb
[3]);
510 i82975x_printk(KERN_INFO
, "DRBCH1R0 = 0x%02x\n", c1drb
[0]);
511 i82975x_printk(KERN_INFO
, "DRBCH1R1 = 0x%02x\n", c1drb
[1]);
512 i82975x_printk(KERN_INFO
, "DRBCH1R2 = 0x%02x\n", c1drb
[2]);
513 i82975x_printk(KERN_INFO
, "DRBCH1R3 = 0x%02x\n", c1drb
[3]);
516 drc
[0] = readl(mch_window
+ I82975X_DRC_CH0M0
);
517 drc
[1] = readl(mch_window
+ I82975X_DRC_CH1M0
);
518 #ifdef i82975x_DEBUG_IOMEM
519 i82975x_printk(KERN_INFO
, "DRC_CH0 = %0x, %s\n", drc
[0],
520 ((drc
[0] >> 21) & 3) == 1 ?
521 "ECC enabled" : "ECC disabled");
522 i82975x_printk(KERN_INFO
, "DRC_CH1 = %0x, %s\n", drc
[1],
523 ((drc
[1] >> 21) & 3) == 1 ?
524 "ECC enabled" : "ECC disabled");
526 i82975x_printk(KERN_INFO
, "C0 BNKARC = %0x\n",
527 readw(mch_window
+ I82975X_C0BNKARC
));
528 i82975x_printk(KERN_INFO
, "C1 BNKARC = %0x\n",
529 readw(mch_window
+ I82975X_C1BNKARC
));
530 i82975x_print_dram_timings(mch_window
);
533 if (!(((drc
[0] >> 21) & 3) == 1 || ((drc
[1] >> 21) & 3) == 1)) {
534 i82975x_printk(KERN_INFO
, "ECC disabled on both channels.\n");
538 chans
= dual_channel_active(mch_window
) + 1;
540 /* assuming only one controller, index thus is 0 */
541 layers
[0].type
= EDAC_MC_LAYER_CHIP_SELECT
;
542 layers
[0].size
= I82975X_NR_DIMMS
;
543 layers
[0].is_virt_csrow
= true;
544 layers
[1].type
= EDAC_MC_LAYER_CHANNEL
;
545 layers
[1].size
= I82975X_NR_CSROWS(chans
);
546 layers
[1].is_virt_csrow
= false;
547 mci
= edac_mc_alloc(0, ARRAY_SIZE(layers
), layers
, sizeof(*pvt
));
553 edac_dbg(3, "init mci\n");
554 mci
->pdev
= &pdev
->dev
;
555 mci
->mtype_cap
= MEM_FLAG_DDR2
;
556 mci
->edac_ctl_cap
= EDAC_FLAG_NONE
| EDAC_FLAG_SECDED
;
557 mci
->edac_cap
= EDAC_FLAG_NONE
| EDAC_FLAG_SECDED
;
558 mci
->mod_name
= EDAC_MOD_STR
;
559 mci
->ctl_name
= i82975x_devs
[dev_idx
].ctl_name
;
560 mci
->dev_name
= pci_name(pdev
);
561 mci
->edac_check
= i82975x_check
;
562 mci
->ctl_page_to_phys
= NULL
;
563 edac_dbg(3, "init pvt\n");
564 pvt
= (struct i82975x_pvt
*) mci
->pvt_info
;
565 pvt
->mch_window
= mch_window
;
566 i82975x_init_csrows(mci
, pdev
, mch_window
);
567 mci
->scrub_mode
= SCRUB_HW_SRC
;
568 i82975x_get_error_info(mci
, &discard
); /* clear counters */
570 /* finalize this instance of memory controller with edac core */
571 if (edac_mc_add_mc(mci
)) {
572 edac_dbg(3, "failed edac_mc_add_mc()\n");
576 /* get this far and it's successful */
577 edac_dbg(3, "success\n");
589 /* returns count (>= 0), or negative on error */
590 static int i82975x_init_one(struct pci_dev
*pdev
,
591 const struct pci_device_id
*ent
)
597 if (pci_enable_device(pdev
) < 0)
600 rc
= i82975x_probe1(pdev
, ent
->driver_data
);
602 if (mci_pdev
== NULL
)
603 mci_pdev
= pci_dev_get(pdev
);
608 static void i82975x_remove_one(struct pci_dev
*pdev
)
610 struct mem_ctl_info
*mci
;
611 struct i82975x_pvt
*pvt
;
615 mci
= edac_mc_del_mc(&pdev
->dev
);
621 iounmap( pvt
->mch_window
);
626 static const struct pci_device_id i82975x_pci_tbl
[] = {
628 PCI_VEND_DEV(INTEL
, 82975_0
), PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
633 } /* 0 terminated list. */
636 MODULE_DEVICE_TABLE(pci
, i82975x_pci_tbl
);
638 static struct pci_driver i82975x_driver
= {
639 .name
= EDAC_MOD_STR
,
640 .probe
= i82975x_init_one
,
641 .remove
= i82975x_remove_one
,
642 .id_table
= i82975x_pci_tbl
,
645 static int __init
i82975x_init(void)
651 /* Ensure that the OPSTATE is set correctly for POLL or NMI */
654 pci_rc
= pci_register_driver(&i82975x_driver
);
658 if (mci_pdev
== NULL
) {
659 mci_pdev
= pci_get_device(PCI_VENDOR_ID_INTEL
,
660 PCI_DEVICE_ID_INTEL_82975_0
, NULL
);
663 edac_dbg(0, "i82975x pci_get_device fail\n");
668 pci_rc
= i82975x_init_one(mci_pdev
, i82975x_pci_tbl
);
671 edac_dbg(0, "i82975x init fail\n");
680 pci_unregister_driver(&i82975x_driver
);
683 pci_dev_put(mci_pdev
);
687 static void __exit
i82975x_exit(void)
691 pci_unregister_driver(&i82975x_driver
);
693 if (!i82975x_registered
) {
694 i82975x_remove_one(mci_pdev
);
695 pci_dev_put(mci_pdev
);
699 module_init(i82975x_init
);
700 module_exit(i82975x_exit
);
702 MODULE_LICENSE("GPL");
703 MODULE_AUTHOR("Arvind R. <arvino55@gmail.com>");
704 MODULE_DESCRIPTION("MC support for Intel 82975 memory hub controllers");
706 module_param(edac_op_state
, int, 0444);
707 MODULE_PARM_DESC(edac_op_state
, "EDAC Error Reporting state: 0=Poll,1=NMI");