2 * Intel e752x Memory Controller kernel module
3 * (C) 2004 Linux Networx (http://lnxi.com)
4 * This file may be distributed under the terms of the
5 * GNU General Public License.
7 * See "enum e752x_chips" below for supported chipsets
9 * Written by Tom Zimmerman
12 * Thayne Harbaugh at realmsys.com (?)
13 * Wang Zhenyu at intel.com
14 * Dave Jiang at mvista.com
16 * $Id: edac_e752x.c,v 1.5.2.11 2005/10/05 00:43:44 dsp_llnl Exp $
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/pci.h>
23 #include <linux/pci_ids.h>
24 #include <linux/slab.h>
25 #include <linux/edac.h>
28 #define E752X_REVISION " Ver: 2.0.1 " __DATE__
29 #define EDAC_MOD_STR "e752x_edac"
31 static int force_function_unhide;
33 #define e752x_printk(level, fmt, arg...) \
34 edac_printk(level, "e752x", fmt, ##arg)
36 #define e752x_mc_printk(mci, level, fmt, arg...) \
37 edac_mc_chipset_printk(mci, level, "e752x", fmt, ##arg)
39 #ifndef PCI_DEVICE_ID_INTEL_7520_0
40 #define PCI_DEVICE_ID_INTEL_7520_0 0x3590
41 #endif /* PCI_DEVICE_ID_INTEL_7520_0 */
43 #ifndef PCI_DEVICE_ID_INTEL_7520_1_ERR
44 #define PCI_DEVICE_ID_INTEL_7520_1_ERR 0x3591
45 #endif /* PCI_DEVICE_ID_INTEL_7520_1_ERR */
47 #ifndef PCI_DEVICE_ID_INTEL_7525_0
48 #define PCI_DEVICE_ID_INTEL_7525_0 0x359E
49 #endif /* PCI_DEVICE_ID_INTEL_7525_0 */
51 #ifndef PCI_DEVICE_ID_INTEL_7525_1_ERR
52 #define PCI_DEVICE_ID_INTEL_7525_1_ERR 0x3593
53 #endif /* PCI_DEVICE_ID_INTEL_7525_1_ERR */
55 #ifndef PCI_DEVICE_ID_INTEL_7320_0
56 #define PCI_DEVICE_ID_INTEL_7320_0 0x3592
57 #endif /* PCI_DEVICE_ID_INTEL_7320_0 */
59 #ifndef PCI_DEVICE_ID_INTEL_7320_1_ERR
60 #define PCI_DEVICE_ID_INTEL_7320_1_ERR 0x3593
61 #endif /* PCI_DEVICE_ID_INTEL_7320_1_ERR */
63 #define E752X_NR_CSROWS 8 /* number of csrows */
65 /* E752X register addresses - device 0 function 0 */
66 #define E752X_DRB 0x60 /* DRAM row boundary register (8b) */
67 #define E752X_DRA 0x70 /* DRAM row attribute register (8b) */
69 * 31:30 Device width row 7
70 * 01=x8 10=x4 11=x8 DDR2
71 * 27:26 Device width row 6
72 * 23:22 Device width row 5
73 * 19:20 Device width row 4
74 * 15:14 Device width row 3
75 * 11:10 Device width row 2
76 * 7:6 Device width row 1
77 * 3:2 Device width row 0
79 #define E752X_DRC 0x7C /* DRAM controller mode reg (32b) */
80 /* FIXME:IS THIS RIGHT? */
82 * 22 Number channels 0=1,1=2
83 * 19:18 DRB Granularity 32/64MB
85 #define E752X_DRM 0x80 /* Dimm mapping register */
86 #define E752X_DDRCSR 0x9A /* DDR control and status reg (16b) */
88 * 14:12 1 single A, 2 single B, 3 dual
90 #define E752X_TOLM 0xC4 /* DRAM top of low memory reg (16b) */
91 #define E752X_REMAPBASE 0xC6 /* DRAM remap base address reg (16b) */
92 #define E752X_REMAPLIMIT 0xC8 /* DRAM remap limit address reg (16b) */
93 #define E752X_REMAPOFFSET 0xCA /* DRAM remap limit offset reg (16b) */
95 /* E752X register addresses - device 0 function 1 */
96 #define E752X_FERR_GLOBAL 0x40 /* Global first error register (32b) */
97 #define E752X_NERR_GLOBAL 0x44 /* Global next error register (32b) */
98 #define E752X_HI_FERR 0x50 /* Hub interface first error reg (8b) */
99 #define E752X_HI_NERR 0x52 /* Hub interface next error reg (8b) */
100 #define E752X_HI_ERRMASK 0x54 /* Hub interface error mask reg (8b) */
101 #define E752X_HI_SMICMD 0x5A /* Hub interface SMI command reg (8b) */
102 #define E752X_SYSBUS_FERR 0x60 /* System buss first error reg (16b) */
103 #define E752X_SYSBUS_NERR 0x62 /* System buss next error reg (16b) */
104 #define E752X_SYSBUS_ERRMASK 0x64 /* System buss error mask reg (16b) */
105 #define E752X_SYSBUS_SMICMD 0x6A /* System buss SMI command reg (16b) */
106 #define E752X_BUF_FERR 0x70 /* Memory buffer first error reg (8b) */
107 #define E752X_BUF_NERR 0x72 /* Memory buffer next error reg (8b) */
108 #define E752X_BUF_ERRMASK 0x74 /* Memory buffer error mask reg (8b) */
109 #define E752X_BUF_SMICMD 0x7A /* Memory buffer SMI command reg (8b) */
110 #define E752X_DRAM_FERR 0x80 /* DRAM first error register (16b) */
111 #define E752X_DRAM_NERR 0x82 /* DRAM next error register (16b) */
112 #define E752X_DRAM_ERRMASK 0x84 /* DRAM error mask register (8b) */
113 #define E752X_DRAM_SMICMD 0x8A /* DRAM SMI command register (8b) */
114 #define E752X_DRAM_RETR_ADD 0xAC /* DRAM Retry address register (32b) */
115 #define E752X_DRAM_SEC1_ADD 0xA0 /* DRAM first correctable memory */
116 /* error address register (32b) */
119 * 30:2 CE address (64 byte block 34:6)
123 #define E752X_DRAM_SEC2_ADD 0xC8 /* DRAM first correctable memory */
124 /* error address register (32b) */
127 * 30:2 CE address (64 byte block 34:6)
131 #define E752X_DRAM_DED_ADD 0xA4 /* DRAM first uncorrectable memory */
132 /* error address register (32b) */
135 * 30:2 CE address (64 byte block 34:6)
139 #define E752X_DRAM_SCRB_ADD 0xA8 /* DRAM first uncorrectable scrub memory */
140 /* error address register (32b) */
143 * 30:2 CE address (64 byte block 34:6)
147 #define E752X_DRAM_SEC1_SYNDROME 0xC4 /* DRAM first correctable memory */
148 /* error syndrome register (16b) */
149 #define E752X_DRAM_SEC2_SYNDROME 0xC6 /* DRAM second correctable memory */
150 /* error syndrome register (16b) */
151 #define E752X_DEVPRES1 0xF4 /* Device Present 1 register (8b) */
153 /* ICH5R register addresses - device 30 function 0 */
154 #define ICH5R_PCI_STAT 0x06 /* PCI status register (16b) */
155 #define ICH5R_PCI_2ND_STAT 0x1E /* PCI status secondary reg (16b) */
156 #define ICH5R_PCI_BRIDGE_CTL 0x3E /* PCI bridge control register (16b) */
165 struct pci_dev *bridge_ck;
166 struct pci_dev *dev_d0f0;
167 struct pci_dev *dev_d0f1;
174 const struct e752x_dev_info *dev_info;
177 struct e752x_dev_info {
180 const char *ctl_name;
183 struct e752x_error_info {
196 u16 dram_sec1_syndrome;
197 u16 dram_sec2_syndrome;
203 static const struct e752x_dev_info e752x_devs[] = {
205 .err_dev = PCI_DEVICE_ID_INTEL_7520_1_ERR,
206 .ctl_dev = PCI_DEVICE_ID_INTEL_7520_0,
210 .err_dev = PCI_DEVICE_ID_INTEL_7525_1_ERR,
211 .ctl_dev = PCI_DEVICE_ID_INTEL_7525_0,
215 .err_dev = PCI_DEVICE_ID_INTEL_7320_1_ERR,
216 .ctl_dev = PCI_DEVICE_ID_INTEL_7320_0,
221 static unsigned long ctl_page_to_phys(struct mem_ctl_info *mci,
225 struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info;
227 debugf3("%s()\n", __func__);
229 if (page < pvt->tolm)
232 if ((page >= 0x100000) && (page < pvt->remapbase))
235 remap = (page - pvt->tolm) + pvt->remapbase;
237 if (remap < pvt->remaplimit)
240 e752x_printk(KERN_ERR, "Invalid page %lx - out of range\n", page);
241 return pvt->tolm - 1;
244 static void do_process_ce(struct mem_ctl_info *mci, u16 error_one,
245 u32 sec1_add, u16 sec1_syndrome)
251 struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info;
253 debugf3("%s()\n", __func__);
255 /* convert the addr to 4k page */
256 page = sec1_add >> (PAGE_SHIFT - 4);
258 /* FIXME - check for -1 */
259 if (pvt->mc_symmetric) {
260 /* chip select are bits 14 & 13 */
261 row = ((page >> 1) & 3);
262 e752x_printk(KERN_WARNING,
263 "Test row %d Table %d %d %d %d %d %d %d %d\n", row,
264 pvt->map[0], pvt->map[1], pvt->map[2], pvt->map[3],
265 pvt->map[4], pvt->map[5], pvt->map[6], pvt->map[7]);
267 /* test for channel remapping */
268 for (i = 0; i < 8; i++) {
269 if (pvt->map[i] == row)
273 e752x_printk(KERN_WARNING, "Test computed row %d\n", i);
278 e752x_mc_printk(mci, KERN_WARNING,
279 "row %d not found in remap table\n", row);
281 row = edac_mc_find_csrow_by_page(mci, page);
283 /* 0 = channel A, 1 = channel B */
284 channel = !(error_one & 1);
289 /* e752x mc reads 34:6 of the DRAM linear address */
290 edac_mc_handle_ce(mci, page, offset_in_page(sec1_add << 4),
291 sec1_syndrome, row, channel, "e752x CE");
294 static inline void process_ce(struct mem_ctl_info *mci, u16 error_one,
295 u32 sec1_add, u16 sec1_syndrome, int *error_found,
301 do_process_ce(mci, error_one, sec1_add, sec1_syndrome);
304 static void do_process_ue(struct mem_ctl_info *mci, u16 error_one,
305 u32 ded_add, u32 scrb_add)
307 u32 error_2b, block_page;
309 struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info;
311 debugf3("%s()\n", __func__);
313 if (error_one & 0x0202) {
316 /* convert to 4k address */
317 block_page = error_2b >> (PAGE_SHIFT - 4);
319 row = pvt->mc_symmetric ?
320 /* chip select are bits 14 & 13 */
321 ((block_page >> 1) & 3) :
322 edac_mc_find_csrow_by_page(mci, block_page);
324 /* e752x mc reads 34:6 of the DRAM linear address */
325 edac_mc_handle_ue(mci, block_page,
326 offset_in_page(error_2b << 4),
327 row, "e752x UE from Read");
329 if (error_one & 0x0404) {
332 /* convert to 4k address */
333 block_page = error_2b >> (PAGE_SHIFT - 4);
335 row = pvt->mc_symmetric ?
336 /* chip select are bits 14 & 13 */
337 ((block_page >> 1) & 3) :
338 edac_mc_find_csrow_by_page(mci, block_page);
340 /* e752x mc reads 34:6 of the DRAM linear address */
341 edac_mc_handle_ue(mci, block_page,
342 offset_in_page(error_2b << 4),
343 row, "e752x UE from Scruber");
347 static inline void process_ue(struct mem_ctl_info *mci, u16 error_one,
348 u32 ded_add, u32 scrb_add, int *error_found, int handle_error)
353 do_process_ue(mci, error_one, ded_add, scrb_add);
356 static inline void process_ue_no_info_wr(struct mem_ctl_info *mci,
357 int *error_found, int handle_error)
364 debugf3("%s()\n", __func__);
365 edac_mc_handle_ue_no_info(mci, "e752x UE log memory write");
368 static void do_process_ded_retry(struct mem_ctl_info *mci, u16 error,
373 struct e752x_pvt *pvt = (struct e752x_pvt *) mci->pvt_info;
375 error_1b = retry_add;
376 page = error_1b >> (PAGE_SHIFT - 4); /* convert the addr to 4k page */
377 row = pvt->mc_symmetric ?
378 ((page >> 1) & 3) : /* chip select are bits 14 & 13 */
379 edac_mc_find_csrow_by_page(mci, page);
380 e752x_mc_printk(mci, KERN_WARNING,
381 "CE page 0x%lx, row %d : Memory read retry\n",
382 (long unsigned int) page, row);
385 static inline void process_ded_retry(struct mem_ctl_info *mci, u16 error,
386 u32 retry_add, int *error_found, int handle_error)
391 do_process_ded_retry(mci, error, retry_add);
394 static inline void process_threshold_ce(struct mem_ctl_info *mci, u16 error,
395 int *error_found, int handle_error)
400 e752x_mc_printk(mci, KERN_WARNING, "Memory threshold CE\n");
403 static char *global_message[11] = {
404 "PCI Express C1", "PCI Express C", "PCI Express B1",
405 "PCI Express B", "PCI Express A1", "PCI Express A",
406 "DMA Controler", "HUB Interface", "System Bus",
407 "DRAM Controler", "Internal Buffer"
410 static char *fatal_message[2] = { "Non-Fatal ", "Fatal " };
412 static void do_global_error(int fatal, u32 errors)
416 for (i = 0; i < 11; i++) {
417 if (errors & (1 << i))
418 e752x_printk(KERN_WARNING, "%sError %s\n",
419 fatal_message[fatal], global_message[i]);
423 static inline void global_error(int fatal, u32 errors, int *error_found,
429 do_global_error(fatal, errors);
432 static char *hub_message[7] = {
433 "HI Address or Command Parity", "HI Illegal Access",
434 "HI Internal Parity", "Out of Range Access",
435 "HI Data Parity", "Enhanced Config Access",
436 "Hub Interface Target Abort"
439 static void do_hub_error(int fatal, u8 errors)
443 for (i = 0; i < 7; i++) {
444 if (errors & (1 << i))
445 e752x_printk(KERN_WARNING, "%sError %s\n",
446 fatal_message[fatal], hub_message[i]);
450 static inline void hub_error(int fatal, u8 errors, int *error_found,
456 do_hub_error(fatal, errors);
459 static char *membuf_message[4] = {
460 "Internal PMWB to DRAM parity",
461 "Internal PMWB to System Bus Parity",
462 "Internal System Bus or IO to PMWB Parity",
463 "Internal DRAM to PMWB Parity"
466 static void do_membuf_error(u8 errors)
470 for (i = 0; i < 4; i++) {
471 if (errors & (1 << i))
472 e752x_printk(KERN_WARNING, "Non-Fatal Error %s\n",
477 static inline void membuf_error(u8 errors, int *error_found, int handle_error)
482 do_membuf_error(errors);
485 static char *sysbus_message[10] = {
486 "Addr or Request Parity",
487 "Data Strobe Glitch",
488 "Addr Strobe Glitch",
491 "Non DRAM Lock Error",
494 "IO Subsystem Parity"
497 static void do_sysbus_error(int fatal, u32 errors)
501 for (i = 0; i < 10; i++) {
502 if (errors & (1 << i))
503 e752x_printk(KERN_WARNING, "%sError System Bus %s\n",
504 fatal_message[fatal], sysbus_message[i]);
508 static inline void sysbus_error(int fatal, u32 errors, int *error_found,
514 do_sysbus_error(fatal, errors);
517 static void e752x_check_hub_interface(struct e752x_error_info *info,
518 int *error_found, int handle_error)
522 //pci_read_config_byte(dev,E752X_HI_FERR,&stat8);
524 stat8 = info->hi_ferr;
526 if(stat8 & 0x7f) { /* Error, so process */
530 hub_error(1, stat8 & 0x2b, error_found, handle_error);
533 hub_error(0, stat8 & 0x54, error_found, handle_error);
536 //pci_read_config_byte(dev,E752X_HI_NERR,&stat8);
538 stat8 = info->hi_nerr;
540 if(stat8 & 0x7f) { /* Error, so process */
544 hub_error(1, stat8 & 0x2b, error_found, handle_error);
547 hub_error(0, stat8 & 0x54, error_found, handle_error);
551 static void e752x_check_sysbus(struct e752x_error_info *info,
552 int *error_found, int handle_error)
556 //pci_read_config_dword(dev,E752X_SYSBUS_FERR,&stat32);
557 stat32 = info->sysbus_ferr + (info->sysbus_nerr << 16);
560 return; /* no errors */
562 error32 = (stat32 >> 16) & 0x3ff;
563 stat32 = stat32 & 0x3ff;
566 sysbus_error(1, stat32 & 0x087, error_found, handle_error);
569 sysbus_error(0, stat32 & 0x378, error_found, handle_error);
572 sysbus_error(1, error32 & 0x087, error_found, handle_error);
575 sysbus_error(0, error32 & 0x378, error_found, handle_error);
578 static void e752x_check_membuf (struct e752x_error_info *info,
579 int *error_found, int handle_error)
583 stat8 = info->buf_ferr;
585 if (stat8 & 0x0f) { /* Error, so process */
587 membuf_error(stat8, error_found, handle_error);
590 stat8 = info->buf_nerr;
592 if (stat8 & 0x0f) { /* Error, so process */
594 membuf_error(stat8, error_found, handle_error);
598 static void e752x_check_dram (struct mem_ctl_info *mci,
599 struct e752x_error_info *info, int *error_found,
602 u16 error_one, error_next;
604 error_one = info->dram_ferr;
605 error_next = info->dram_nerr;
607 /* decode and report errors */
608 if(error_one & 0x0101) /* check first error correctable */
609 process_ce(mci, error_one, info->dram_sec1_add,
610 info->dram_sec1_syndrome, error_found,
613 if(error_next & 0x0101) /* check next error correctable */
614 process_ce(mci, error_next, info->dram_sec2_add,
615 info->dram_sec2_syndrome, error_found,
618 if(error_one & 0x4040)
619 process_ue_no_info_wr(mci, error_found, handle_error);
621 if(error_next & 0x4040)
622 process_ue_no_info_wr(mci, error_found, handle_error);
624 if(error_one & 0x2020)
625 process_ded_retry(mci, error_one, info->dram_retr_add,
626 error_found, handle_error);
628 if(error_next & 0x2020)
629 process_ded_retry(mci, error_next, info->dram_retr_add,
630 error_found, handle_error);
632 if(error_one & 0x0808)
633 process_threshold_ce(mci, error_one, error_found,
636 if(error_next & 0x0808)
637 process_threshold_ce(mci, error_next, error_found,
640 if(error_one & 0x0606)
641 process_ue(mci, error_one, info->dram_ded_add,
642 info->dram_scrb_add, error_found, handle_error);
644 if(error_next & 0x0606)
645 process_ue(mci, error_next, info->dram_ded_add,
646 info->dram_scrb_add, error_found, handle_error);
649 static void e752x_get_error_info (struct mem_ctl_info *mci,
650 struct e752x_error_info *info)
653 struct e752x_pvt *pvt;
655 memset(info, 0, sizeof(*info));
656 pvt = (struct e752x_pvt *) mci->pvt_info;
658 pci_read_config_dword(dev, E752X_FERR_GLOBAL, &info->ferr_global);
660 if (info->ferr_global) {
661 pci_read_config_byte(dev, E752X_HI_FERR, &info->hi_ferr);
662 pci_read_config_word(dev, E752X_SYSBUS_FERR,
664 pci_read_config_byte(dev, E752X_BUF_FERR, &info->buf_ferr);
665 pci_read_config_word(dev, E752X_DRAM_FERR,
667 pci_read_config_dword(dev, E752X_DRAM_SEC1_ADD,
668 &info->dram_sec1_add);
669 pci_read_config_word(dev, E752X_DRAM_SEC1_SYNDROME,
670 &info->dram_sec1_syndrome);
671 pci_read_config_dword(dev, E752X_DRAM_DED_ADD,
672 &info->dram_ded_add);
673 pci_read_config_dword(dev, E752X_DRAM_SCRB_ADD,
674 &info->dram_scrb_add);
675 pci_read_config_dword(dev, E752X_DRAM_RETR_ADD,
676 &info->dram_retr_add);
678 if (info->hi_ferr & 0x7f)
679 pci_write_config_byte(dev, E752X_HI_FERR,
682 if (info->sysbus_ferr)
683 pci_write_config_word(dev, E752X_SYSBUS_FERR,
686 if (info->buf_ferr & 0x0f)
687 pci_write_config_byte(dev, E752X_BUF_FERR,
691 pci_write_bits16(pvt->bridge_ck, E752X_DRAM_FERR,
692 info->dram_ferr, info->dram_ferr);
694 pci_write_config_dword(dev, E752X_FERR_GLOBAL,
698 pci_read_config_dword(dev, E752X_NERR_GLOBAL, &info->nerr_global);
700 if (info->nerr_global) {
701 pci_read_config_byte(dev, E752X_HI_NERR, &info->hi_nerr);
702 pci_read_config_word(dev, E752X_SYSBUS_NERR,
704 pci_read_config_byte(dev, E752X_BUF_NERR, &info->buf_nerr);
705 pci_read_config_word(dev, E752X_DRAM_NERR,
707 pci_read_config_dword(dev, E752X_DRAM_SEC2_ADD,
708 &info->dram_sec2_add);
709 pci_read_config_word(dev, E752X_DRAM_SEC2_SYNDROME,
710 &info->dram_sec2_syndrome);
712 if (info->hi_nerr & 0x7f)
713 pci_write_config_byte(dev, E752X_HI_NERR,
716 if (info->sysbus_nerr)
717 pci_write_config_word(dev, E752X_SYSBUS_NERR,
720 if (info->buf_nerr & 0x0f)
721 pci_write_config_byte(dev, E752X_BUF_NERR,
725 pci_write_bits16(pvt->bridge_ck, E752X_DRAM_NERR,
726 info->dram_nerr, info->dram_nerr);
728 pci_write_config_dword(dev, E752X_NERR_GLOBAL,
733 static int e752x_process_error_info (struct mem_ctl_info *mci,
734 struct e752x_error_info *info, int handle_errors)
740 error32 = (info->ferr_global >> 18) & 0x3ff;
741 stat32 = (info->ferr_global >> 4) & 0x7ff;
744 global_error(1, error32, &error_found, handle_errors);
747 global_error(0, stat32, &error_found, handle_errors);
749 error32 = (info->nerr_global >> 18) & 0x3ff;
750 stat32 = (info->nerr_global >> 4) & 0x7ff;
753 global_error(1, error32, &error_found, handle_errors);
756 global_error(0, stat32, &error_found, handle_errors);
758 e752x_check_hub_interface(info, &error_found, handle_errors);
759 e752x_check_sysbus(info, &error_found, handle_errors);
760 e752x_check_membuf(info, &error_found, handle_errors);
761 e752x_check_dram(mci, info, &error_found, handle_errors);
765 static void e752x_check(struct mem_ctl_info *mci)
767 struct e752x_error_info info;
769 debugf3("%s()\n", __func__);
770 e752x_get_error_info(mci, &info);
771 e752x_process_error_info(mci, &info, 1);
774 /* Return 1 if dual channel mode is active. Else return 0. */
775 static inline int dual_channel_active(u16 ddrcsr)
777 return (((ddrcsr >> 12) & 3) == 3);
780 static void e752x_init_csrows(struct mem_ctl_info *mci, struct pci_dev *pdev,
783 struct csrow_info *csrow;
784 unsigned long last_cumul_size;
785 int index, mem_dev, drc_chan;
786 int drc_drbg; /* DRB granularity 0=64mb, 1=128mb */
787 int drc_ddim; /* DRAM Data Integrity Mode 0=none, 2=edac */
789 u32 dra, drc, cumul_size;
792 for (index=0; index < 4; index++) {
794 pci_read_config_byte(pdev, E752X_DRA+index, &dra_reg);
795 dra |= dra_reg << (index * 8);
797 pci_read_config_dword(pdev, E752X_DRC, &drc);
798 drc_chan = dual_channel_active(ddrcsr);
799 drc_drbg = drc_chan + 1; /* 128 in dual mode, 64 in single */
800 drc_ddim = (drc >> 20) & 0x3;
802 /* The dram row boundary (DRB) reg values are boundary address for
803 * each DRAM row with a granularity of 64 or 128MB (single/dual
804 * channel operation). DRB regs are cumulative; therefore DRB7 will
805 * contain the total memory contained in all eight rows.
807 for (last_cumul_size = index = 0; index < mci->nr_csrows; index++) {
808 /* mem_dev 0=x8, 1=x4 */
809 mem_dev = (dra >> (index * 4 + 2)) & 0x3;
810 csrow = &mci->csrows[index];
812 mem_dev = (mem_dev == 2);
813 pci_read_config_byte(pdev, E752X_DRB + index, &value);
814 /* convert a 128 or 64 MiB DRB to a page size. */
815 cumul_size = value << (25 + drc_drbg - PAGE_SHIFT);
816 debugf3("%s(): (%d) cumul_size 0x%x\n", __func__, index,
818 if (cumul_size == last_cumul_size)
819 continue; /* not populated */
821 csrow->first_page = last_cumul_size;
822 csrow->last_page = cumul_size - 1;
823 csrow->nr_pages = cumul_size - last_cumul_size;
824 last_cumul_size = cumul_size;
825 csrow->grain = 1 << 12; /* 4KiB - resolution of CELOG */
826 csrow->mtype = MEM_RDDR; /* only one type supported */
827 csrow->dtype = mem_dev ? DEV_X4 : DEV_X8;
830 * if single channel or x8 devices then SECDED
831 * if dual channel and x4 then S4ECD4ED
834 if (drc_chan && mem_dev) {
835 csrow->edac_mode = EDAC_S4ECD4ED;
836 mci->edac_cap |= EDAC_FLAG_S4ECD4ED;
838 csrow->edac_mode = EDAC_SECDED;
839 mci->edac_cap |= EDAC_FLAG_SECDED;
842 csrow->edac_mode = EDAC_NONE;
846 static void e752x_init_mem_map_table(struct pci_dev *pdev,
847 struct e752x_pvt *pvt)
850 u8 value, last, row, stat8;
855 for (index = 0; index < 8; index += 2) {
856 pci_read_config_byte(pdev, E752X_DRB + index, &value);
857 /* test if there is a dimm in this slot */
859 /* no dimm in the slot, so flag it as empty */
860 pvt->map[index] = 0xff;
861 pvt->map[index + 1] = 0xff;
862 } else { /* there is a dimm in the slot */
863 pvt->map[index] = row;
866 /* test the next value to see if the dimm is double
869 pci_read_config_byte(pdev, E752X_DRB + index + 1,
871 pvt->map[index + 1] = (value == last) ?
872 0xff : /* the dimm is single sided,
874 row; /* this is a double sided dimm
875 to save the next row # */
881 /* set the map type. 1 = normal, 0 = reversed */
882 pci_read_config_byte(pdev, E752X_DRM, &stat8);
883 pvt->map_type = ((stat8 & 0x0f) > ((stat8 >> 4) & 0x0f));
886 /* Return 0 on success or 1 on failure. */
887 static int e752x_get_devs(struct pci_dev *pdev, int dev_idx,
888 struct e752x_pvt *pvt)
892 pvt->bridge_ck = pci_get_device(PCI_VENDOR_ID_INTEL,
893 pvt->dev_info->err_dev,
896 if (pvt->bridge_ck == NULL)
897 pvt->bridge_ck = pci_scan_single_device(pdev->bus,
900 if (pvt->bridge_ck == NULL) {
901 e752x_printk(KERN_ERR, "error reporting device not found:"
902 "vendor %x device 0x%x (broken BIOS?)\n",
903 PCI_VENDOR_ID_INTEL, e752x_devs[dev_idx].err_dev);
907 dev = pci_get_device(PCI_VENDOR_ID_INTEL, e752x_devs[dev_idx].ctl_dev,
914 pvt->dev_d0f1 = pci_dev_get(pvt->bridge_ck);
919 pci_dev_put(pvt->bridge_ck);
923 static void e752x_init_error_reporting_regs(struct e752x_pvt *pvt)
928 /* Turn off error disable & SMI in case the BIOS turned it on */
929 pci_write_config_byte(dev, E752X_HI_ERRMASK, 0x00);
930 pci_write_config_byte(dev, E752X_HI_SMICMD, 0x00);
931 pci_write_config_word(dev, E752X_SYSBUS_ERRMASK, 0x00);
932 pci_write_config_word(dev, E752X_SYSBUS_SMICMD, 0x00);
933 pci_write_config_byte(dev, E752X_BUF_ERRMASK, 0x00);
934 pci_write_config_byte(dev, E752X_BUF_SMICMD, 0x00);
935 pci_write_config_byte(dev, E752X_DRAM_ERRMASK, 0x00);
936 pci_write_config_byte(dev, E752X_DRAM_SMICMD, 0x00);
939 static int e752x_probe1(struct pci_dev *pdev, int dev_idx)
943 struct mem_ctl_info *mci;
944 struct e752x_pvt *pvt;
946 int drc_chan; /* Number of channels 0=1chan,1=2chan */
947 struct e752x_error_info discard;
949 debugf0("%s(): mci\n", __func__);
950 debugf0("Starting Probe1\n");
952 /* make sure error reporting method is sane */
953 switch(edac_op_state) {
954 case EDAC_OPSTATE_POLL:
955 case EDAC_OPSTATE_NMI:
958 edac_op_state = EDAC_OPSTATE_POLL;
962 /* check to see if device 0 function 1 is enabled; if it isn't, we
963 * assume the BIOS has reserved it for a reason and is expecting
964 * exclusive access, we take care not to violate that assumption and
966 pci_read_config_byte(pdev, E752X_DEVPRES1, &stat8);
967 if (!force_function_unhide && !(stat8 & (1 << 5))) {
968 printk(KERN_INFO "Contact your BIOS vendor to see if the "
969 "E752x error registers can be safely un-hidden\n");
973 pci_write_config_byte(pdev, E752X_DEVPRES1, stat8);
975 pci_read_config_word(pdev, E752X_DDRCSR, &ddrcsr);
976 /* FIXME: should check >>12 or 0xf, true for all? */
977 /* Dual channel = 1, Single channel = 0 */
978 drc_chan = dual_channel_active(ddrcsr);
980 mci = edac_mc_alloc(sizeof(*pvt), E752X_NR_CSROWS, drc_chan + 1);
986 debugf3("%s(): init mci\n", __func__);
987 mci->mtype_cap = MEM_FLAG_RDDR;
988 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED |
990 /* FIXME - what if different memory types are in different csrows? */
991 mci->mod_name = EDAC_MOD_STR;
992 mci->mod_ver = E752X_REVISION;
993 mci->dev = &pdev->dev;
995 debugf3("%s(): init pvt\n", __func__);
996 pvt = (struct e752x_pvt *) mci->pvt_info;
997 pvt->dev_info = &e752x_devs[dev_idx];
998 pvt->mc_symmetric = ((ddrcsr & 0x10) != 0);
1000 if (e752x_get_devs(pdev, dev_idx, pvt)) {
1005 debugf3("%s(): more mci init\n", __func__);
1006 mci->ctl_name = pvt->dev_info->ctl_name;
1007 mci->edac_check = e752x_check;
1008 mci->ctl_page_to_phys = ctl_page_to_phys;
1010 e752x_init_csrows(mci, pdev, ddrcsr);
1011 e752x_init_mem_map_table(pdev, pvt);
1013 /* set the map type. 1 = normal, 0 = reversed */
1014 pci_read_config_byte(pdev, E752X_DRM, &stat8);
1015 pvt->map_type = ((stat8 & 0x0f) > ((stat8 >> 4) & 0x0f));
1017 mci->edac_cap |= EDAC_FLAG_NONE;
1018 debugf3("%s(): tolm, remapbase, remaplimit\n", __func__);
1020 /* load the top of low memory, remap base, and remap limit vars */
1021 pci_read_config_word(pdev, E752X_TOLM, &pci_data);
1022 pvt->tolm = ((u32) pci_data) << 4;
1023 pci_read_config_word(pdev, E752X_REMAPBASE, &pci_data);
1024 pvt->remapbase = ((u32) pci_data) << 14;
1025 pci_read_config_word(pdev, E752X_REMAPLIMIT, &pci_data);
1026 pvt->remaplimit = ((u32) pci_data) << 14;
1027 e752x_printk(KERN_INFO,
1028 "tolm = %x, remapbase = %x, remaplimit = %x\n", pvt->tolm,
1029 pvt->remapbase, pvt->remaplimit);
1031 /* Here we assume that we will never see multiple instances of this
1032 * type of memory controller. The ID is therefore hardcoded to 0.
1034 if (edac_mc_add_mc(mci,0)) {
1035 debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
1039 e752x_init_error_reporting_regs(pvt);
1040 e752x_get_error_info(mci, &discard); /* clear other MCH errors */
1042 /* get this far and it's successful */
1043 debugf3("%s(): success\n", __func__);
1047 pci_dev_put(pvt->dev_d0f0);
1048 pci_dev_put(pvt->dev_d0f1);
1049 pci_dev_put(pvt->bridge_ck);
1055 /* returns count (>= 0), or negative on error */
1056 static int __devinit e752x_init_one(struct pci_dev *pdev,
1057 const struct pci_device_id *ent)
1059 debugf0("%s()\n", __func__);
1061 /* wake up and enable device */
1062 if(pci_enable_device(pdev) < 0)
1065 return e752x_probe1(pdev, ent->driver_data);
1068 static void __devexit e752x_remove_one(struct pci_dev *pdev)
1070 struct mem_ctl_info *mci;
1071 struct e752x_pvt *pvt;
1073 debugf0("%s()\n", __func__);
1075 if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
1078 pvt = (struct e752x_pvt *) mci->pvt_info;
1079 pci_dev_put(pvt->dev_d0f0);
1080 pci_dev_put(pvt->dev_d0f1);
1081 pci_dev_put(pvt->bridge_ck);
1085 static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
1087 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1091 PCI_VEND_DEV(INTEL, 7525_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1095 PCI_VEND_DEV(INTEL, 7320_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1100 } /* 0 terminated list. */
1103 MODULE_DEVICE_TABLE(pci, e752x_pci_tbl);
1105 static struct pci_driver e752x_driver = {
1106 .name = EDAC_MOD_STR,
1107 .probe = e752x_init_one,
1108 .remove = __devexit_p(e752x_remove_one),
1109 .id_table = e752x_pci_tbl,
1112 static int __init e752x_init(void)
1116 debugf3("%s()\n", __func__);
1117 pci_rc = pci_register_driver(&e752x_driver);
1118 return (pci_rc < 0) ? pci_rc : 0;
1121 static void __exit e752x_exit(void)
1123 debugf3("%s()\n", __func__);
1124 pci_unregister_driver(&e752x_driver);
1127 module_init(e752x_init);
1128 module_exit(e752x_exit);
1130 MODULE_LICENSE("GPL");
1131 MODULE_AUTHOR("Linux Networx (http://lnxi.com) Tom Zimmerman\n");
1132 MODULE_DESCRIPTION("MC support for Intel e752x memory controllers");
1134 module_param(force_function_unhide, int, 0444);
1135 MODULE_PARM_DESC(force_function_unhide, "if BIOS sets Dev0:Fun1 up as hidden:"
1136 " 1=force unhide and hope BIOS doesn't fight driver for Dev0:Fun1 access");
1137 module_param(edac_op_state, int, 0444);
1138 MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");