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>
27 #define E752X_REVISION " Ver: 2.0.0 " __DATE__
29 static int force_function_unhide
;
31 #define e752x_printk(level, fmt, arg...) \
32 edac_printk(level, "e752x", fmt, ##arg)
34 #define e752x_mc_printk(mci, level, fmt, arg...) \
35 edac_mc_chipset_printk(mci, level, "e752x", fmt, ##arg)
37 #ifndef PCI_DEVICE_ID_INTEL_7520_0
38 #define PCI_DEVICE_ID_INTEL_7520_0 0x3590
39 #endif /* PCI_DEVICE_ID_INTEL_7520_0 */
41 #ifndef PCI_DEVICE_ID_INTEL_7520_1_ERR
42 #define PCI_DEVICE_ID_INTEL_7520_1_ERR 0x3591
43 #endif /* PCI_DEVICE_ID_INTEL_7520_1_ERR */
45 #ifndef PCI_DEVICE_ID_INTEL_7525_0
46 #define PCI_DEVICE_ID_INTEL_7525_0 0x359E
47 #endif /* PCI_DEVICE_ID_INTEL_7525_0 */
49 #ifndef PCI_DEVICE_ID_INTEL_7525_1_ERR
50 #define PCI_DEVICE_ID_INTEL_7525_1_ERR 0x3593
51 #endif /* PCI_DEVICE_ID_INTEL_7525_1_ERR */
53 #ifndef PCI_DEVICE_ID_INTEL_7320_0
54 #define PCI_DEVICE_ID_INTEL_7320_0 0x3592
55 #endif /* PCI_DEVICE_ID_INTEL_7320_0 */
57 #ifndef PCI_DEVICE_ID_INTEL_7320_1_ERR
58 #define PCI_DEVICE_ID_INTEL_7320_1_ERR 0x3593
59 #endif /* PCI_DEVICE_ID_INTEL_7320_1_ERR */
61 #define E752X_NR_CSROWS 8 /* number of csrows */
63 /* E752X register addresses - device 0 function 0 */
64 #define E752X_DRB 0x60 /* DRAM row boundary register (8b) */
65 #define E752X_DRA 0x70 /* DRAM row attribute register (8b) */
67 * 31:30 Device width row 7
68 * 01=x8 10=x4 11=x8 DDR2
69 * 27:26 Device width row 6
70 * 23:22 Device width row 5
71 * 19:20 Device width row 4
72 * 15:14 Device width row 3
73 * 11:10 Device width row 2
74 * 7:6 Device width row 1
75 * 3:2 Device width row 0
77 #define E752X_DRC 0x7C /* DRAM controller mode reg (32b) */
78 /* FIXME:IS THIS RIGHT? */
80 * 22 Number channels 0=1,1=2
81 * 19:18 DRB Granularity 32/64MB
83 #define E752X_DRM 0x80 /* Dimm mapping register */
84 #define E752X_DDRCSR 0x9A /* DDR control and status reg (16b) */
86 * 14:12 1 single A, 2 single B, 3 dual
88 #define E752X_TOLM 0xC4 /* DRAM top of low memory reg (16b) */
89 #define E752X_REMAPBASE 0xC6 /* DRAM remap base address reg (16b) */
90 #define E752X_REMAPLIMIT 0xC8 /* DRAM remap limit address reg (16b) */
91 #define E752X_REMAPOFFSET 0xCA /* DRAM remap limit offset reg (16b) */
93 /* E752X register addresses - device 0 function 1 */
94 #define E752X_FERR_GLOBAL 0x40 /* Global first error register (32b) */
95 #define E752X_NERR_GLOBAL 0x44 /* Global next error register (32b) */
96 #define E752X_HI_FERR 0x50 /* Hub interface first error reg (8b) */
97 #define E752X_HI_NERR 0x52 /* Hub interface next error reg (8b) */
98 #define E752X_HI_ERRMASK 0x54 /* Hub interface error mask reg (8b) */
99 #define E752X_HI_SMICMD 0x5A /* Hub interface SMI command reg (8b) */
100 #define E752X_SYSBUS_FERR 0x60 /* System buss first error reg (16b) */
101 #define E752X_SYSBUS_NERR 0x62 /* System buss next error reg (16b) */
102 #define E752X_SYSBUS_ERRMASK 0x64 /* System buss error mask reg (16b) */
103 #define E752X_SYSBUS_SMICMD 0x6A /* System buss SMI command reg (16b) */
104 #define E752X_BUF_FERR 0x70 /* Memory buffer first error reg (8b) */
105 #define E752X_BUF_NERR 0x72 /* Memory buffer next error reg (8b) */
106 #define E752X_BUF_ERRMASK 0x74 /* Memory buffer error mask reg (8b) */
107 #define E752X_BUF_SMICMD 0x7A /* Memory buffer SMI command reg (8b) */
108 #define E752X_DRAM_FERR 0x80 /* DRAM first error register (16b) */
109 #define E752X_DRAM_NERR 0x82 /* DRAM next error register (16b) */
110 #define E752X_DRAM_ERRMASK 0x84 /* DRAM error mask register (8b) */
111 #define E752X_DRAM_SMICMD 0x8A /* DRAM SMI command register (8b) */
112 #define E752X_DRAM_RETR_ADD 0xAC /* DRAM Retry address register (32b) */
113 #define E752X_DRAM_SEC1_ADD 0xA0 /* DRAM first correctable memory */
114 /* error address register (32b) */
117 * 30:2 CE address (64 byte block 34:6)
121 #define E752X_DRAM_SEC2_ADD 0xC8 /* DRAM first correctable memory */
122 /* error address register (32b) */
125 * 30:2 CE address (64 byte block 34:6)
129 #define E752X_DRAM_DED_ADD 0xA4 /* DRAM first uncorrectable memory */
130 /* error address register (32b) */
133 * 30:2 CE address (64 byte block 34:6)
137 #define E752X_DRAM_SCRB_ADD 0xA8 /* DRAM first uncorrectable scrub memory */
138 /* error address register (32b) */
141 * 30:2 CE address (64 byte block 34:6)
145 #define E752X_DRAM_SEC1_SYNDROME 0xC4 /* DRAM first correctable memory */
146 /* error syndrome register (16b) */
147 #define E752X_DRAM_SEC2_SYNDROME 0xC6 /* DRAM second correctable memory */
148 /* error syndrome register (16b) */
149 #define E752X_DEVPRES1 0xF4 /* Device Present 1 register (8b) */
151 /* ICH5R register addresses - device 30 function 0 */
152 #define ICH5R_PCI_STAT 0x06 /* PCI status register (16b) */
153 #define ICH5R_PCI_2ND_STAT 0x1E /* PCI status secondary reg (16b) */
154 #define ICH5R_PCI_BRIDGE_CTL 0x3E /* PCI bridge control register (16b) */
163 struct pci_dev
*bridge_ck
;
164 struct pci_dev
*dev_d0f0
;
165 struct pci_dev
*dev_d0f1
;
172 const struct e752x_dev_info
*dev_info
;
175 struct e752x_dev_info
{
178 const char *ctl_name
;
181 struct e752x_error_info
{
194 u16 dram_sec1_syndrome
;
195 u16 dram_sec2_syndrome
;
201 static const struct e752x_dev_info e752x_devs
[] = {
203 .err_dev
= PCI_DEVICE_ID_INTEL_7520_1_ERR
,
204 .ctl_dev
= PCI_DEVICE_ID_INTEL_7520_0
,
208 .err_dev
= PCI_DEVICE_ID_INTEL_7525_1_ERR
,
209 .ctl_dev
= PCI_DEVICE_ID_INTEL_7525_0
,
213 .err_dev
= PCI_DEVICE_ID_INTEL_7320_1_ERR
,
214 .ctl_dev
= PCI_DEVICE_ID_INTEL_7320_0
,
219 static unsigned long ctl_page_to_phys(struct mem_ctl_info
*mci
,
223 struct e752x_pvt
*pvt
= (struct e752x_pvt
*) mci
->pvt_info
;
225 debugf3("%s()\n", __func__
);
227 if (page
< pvt
->tolm
)
230 if ((page
>= 0x100000) && (page
< pvt
->remapbase
))
233 remap
= (page
- pvt
->tolm
) + pvt
->remapbase
;
235 if (remap
< pvt
->remaplimit
)
238 e752x_printk(KERN_ERR
, "Invalid page %lx - out of range\n", page
);
239 return pvt
->tolm
- 1;
242 static void do_process_ce(struct mem_ctl_info
*mci
, u16 error_one
,
243 u32 sec1_add
, u16 sec1_syndrome
)
249 struct e752x_pvt
*pvt
= (struct e752x_pvt
*) mci
->pvt_info
;
251 debugf3("%s()\n", __func__
);
253 /* convert the addr to 4k page */
254 page
= sec1_add
>> (PAGE_SHIFT
- 4);
256 /* FIXME - check for -1 */
257 if (pvt
->mc_symmetric
) {
258 /* chip select are bits 14 & 13 */
259 row
= ((page
>> 1) & 3);
260 e752x_printk(KERN_WARNING
,
261 "Test row %d Table %d %d %d %d %d %d %d %d\n", row
,
262 pvt
->map
[0], pvt
->map
[1], pvt
->map
[2], pvt
->map
[3],
263 pvt
->map
[4], pvt
->map
[5], pvt
->map
[6], pvt
->map
[7]);
265 /* test for channel remapping */
266 for (i
= 0; i
< 8; i
++) {
267 if (pvt
->map
[i
] == row
)
271 e752x_printk(KERN_WARNING
, "Test computed row %d\n", i
);
276 e752x_mc_printk(mci
, KERN_WARNING
,
277 "row %d not found in remap table\n", row
);
279 row
= edac_mc_find_csrow_by_page(mci
, page
);
281 /* 0 = channel A, 1 = channel B */
282 channel
= !(error_one
& 1);
287 edac_mc_handle_ce(mci
, page
, 0, sec1_syndrome
, row
, channel
,
291 static inline void process_ce(struct mem_ctl_info
*mci
, u16 error_one
,
292 u32 sec1_add
, u16 sec1_syndrome
, int *error_found
,
298 do_process_ce(mci
, error_one
, sec1_add
, sec1_syndrome
);
301 static void do_process_ue(struct mem_ctl_info
*mci
, u16 error_one
,
302 u32 ded_add
, u32 scrb_add
)
304 u32 error_2b
, block_page
;
306 struct e752x_pvt
*pvt
= (struct e752x_pvt
*) mci
->pvt_info
;
308 debugf3("%s()\n", __func__
);
310 if (error_one
& 0x0202) {
313 /* convert to 4k address */
314 block_page
= error_2b
>> (PAGE_SHIFT
- 4);
316 row
= pvt
->mc_symmetric
?
317 /* chip select are bits 14 & 13 */
318 ((block_page
>> 1) & 3) :
319 edac_mc_find_csrow_by_page(mci
, block_page
);
321 edac_mc_handle_ue(mci
, block_page
, 0, row
,
322 "e752x UE from Read");
324 if (error_one
& 0x0404) {
327 /* convert to 4k address */
328 block_page
= error_2b
>> (PAGE_SHIFT
- 4);
330 row
= pvt
->mc_symmetric
?
331 /* chip select are bits 14 & 13 */
332 ((block_page
>> 1) & 3) :
333 edac_mc_find_csrow_by_page(mci
, block_page
);
335 edac_mc_handle_ue(mci
, block_page
, 0, row
,
336 "e752x UE from Scruber");
340 static inline void process_ue(struct mem_ctl_info
*mci
, u16 error_one
,
341 u32 ded_add
, u32 scrb_add
, int *error_found
, int handle_error
)
346 do_process_ue(mci
, error_one
, ded_add
, scrb_add
);
349 static inline void process_ue_no_info_wr(struct mem_ctl_info
*mci
,
350 int *error_found
, int handle_error
)
357 debugf3("%s()\n", __func__
);
358 edac_mc_handle_ue_no_info(mci
, "e752x UE log memory write");
361 static void do_process_ded_retry(struct mem_ctl_info
*mci
, u16 error
,
366 struct e752x_pvt
*pvt
= (struct e752x_pvt
*) mci
->pvt_info
;
368 error_1b
= retry_add
;
369 page
= error_1b
>> (PAGE_SHIFT
- 4); /* convert the addr to 4k page */
370 row
= pvt
->mc_symmetric
?
371 ((page
>> 1) & 3) : /* chip select are bits 14 & 13 */
372 edac_mc_find_csrow_by_page(mci
, page
);
373 e752x_mc_printk(mci
, KERN_WARNING
,
374 "CE page 0x%lx, row %d : Memory read retry\n",
375 (long unsigned int) page
, row
);
378 static inline void process_ded_retry(struct mem_ctl_info
*mci
, u16 error
,
379 u32 retry_add
, int *error_found
, int handle_error
)
384 do_process_ded_retry(mci
, error
, retry_add
);
387 static inline void process_threshold_ce(struct mem_ctl_info
*mci
, u16 error
,
388 int *error_found
, int handle_error
)
393 e752x_mc_printk(mci
, KERN_WARNING
, "Memory threshold CE\n");
396 static char *global_message
[11] = {
397 "PCI Express C1", "PCI Express C", "PCI Express B1",
398 "PCI Express B", "PCI Express A1", "PCI Express A",
399 "DMA Controler", "HUB Interface", "System Bus",
400 "DRAM Controler", "Internal Buffer"
403 static char *fatal_message
[2] = { "Non-Fatal ", "Fatal " };
405 static void do_global_error(int fatal
, u32 errors
)
409 for (i
= 0; i
< 11; i
++) {
410 if (errors
& (1 << i
))
411 e752x_printk(KERN_WARNING
, "%sError %s\n",
412 fatal_message
[fatal
], global_message
[i
]);
416 static inline void global_error(int fatal
, u32 errors
, int *error_found
,
422 do_global_error(fatal
, errors
);
425 static char *hub_message
[7] = {
426 "HI Address or Command Parity", "HI Illegal Access",
427 "HI Internal Parity", "Out of Range Access",
428 "HI Data Parity", "Enhanced Config Access",
429 "Hub Interface Target Abort"
432 static void do_hub_error(int fatal
, u8 errors
)
436 for (i
= 0; i
< 7; i
++) {
437 if (errors
& (1 << i
))
438 e752x_printk(KERN_WARNING
, "%sError %s\n",
439 fatal_message
[fatal
], hub_message
[i
]);
443 static inline void hub_error(int fatal
, u8 errors
, int *error_found
,
449 do_hub_error(fatal
, errors
);
452 static char *membuf_message
[4] = {
453 "Internal PMWB to DRAM parity",
454 "Internal PMWB to System Bus Parity",
455 "Internal System Bus or IO to PMWB Parity",
456 "Internal DRAM to PMWB Parity"
459 static void do_membuf_error(u8 errors
)
463 for (i
= 0; i
< 4; i
++) {
464 if (errors
& (1 << i
))
465 e752x_printk(KERN_WARNING
, "Non-Fatal Error %s\n",
470 static inline void membuf_error(u8 errors
, int *error_found
, int handle_error
)
475 do_membuf_error(errors
);
478 static char *sysbus_message
[10] = {
479 "Addr or Request Parity",
480 "Data Strobe Glitch",
481 "Addr Strobe Glitch",
484 "Non DRAM Lock Error",
487 "IO Subsystem Parity"
490 static void do_sysbus_error(int fatal
, u32 errors
)
494 for (i
= 0; i
< 10; i
++) {
495 if (errors
& (1 << i
))
496 e752x_printk(KERN_WARNING
, "%sError System Bus %s\n",
497 fatal_message
[fatal
], sysbus_message
[i
]);
501 static inline void sysbus_error(int fatal
, u32 errors
, int *error_found
,
507 do_sysbus_error(fatal
, errors
);
510 static void e752x_check_hub_interface(struct e752x_error_info
*info
,
511 int *error_found
, int handle_error
)
515 //pci_read_config_byte(dev,E752X_HI_FERR,&stat8);
517 stat8
= info
->hi_ferr
;
519 if(stat8
& 0x7f) { /* Error, so process */
523 hub_error(1, stat8
& 0x2b, error_found
, handle_error
);
526 hub_error(0, stat8
& 0x54, error_found
, handle_error
);
529 //pci_read_config_byte(dev,E752X_HI_NERR,&stat8);
531 stat8
= info
->hi_nerr
;
533 if(stat8
& 0x7f) { /* Error, so process */
537 hub_error(1, stat8
& 0x2b, error_found
, handle_error
);
540 hub_error(0, stat8
& 0x54, error_found
, handle_error
);
544 static void e752x_check_sysbus(struct e752x_error_info
*info
,
545 int *error_found
, int handle_error
)
549 //pci_read_config_dword(dev,E752X_SYSBUS_FERR,&stat32);
550 stat32
= info
->sysbus_ferr
+ (info
->sysbus_nerr
<< 16);
553 return; /* no errors */
555 error32
= (stat32
>> 16) & 0x3ff;
556 stat32
= stat32
& 0x3ff;
559 sysbus_error(1, stat32
& 0x083, error_found
, handle_error
);
562 sysbus_error(0, stat32
& 0x37c, error_found
, handle_error
);
565 sysbus_error(1, error32
& 0x083, error_found
, handle_error
);
568 sysbus_error(0, error32
& 0x37c, error_found
, handle_error
);
571 static void e752x_check_membuf (struct e752x_error_info
*info
,
572 int *error_found
, int handle_error
)
576 stat8
= info
->buf_ferr
;
578 if (stat8
& 0x0f) { /* Error, so process */
580 membuf_error(stat8
, error_found
, handle_error
);
583 stat8
= info
->buf_nerr
;
585 if (stat8
& 0x0f) { /* Error, so process */
587 membuf_error(stat8
, error_found
, handle_error
);
591 static void e752x_check_dram (struct mem_ctl_info
*mci
,
592 struct e752x_error_info
*info
, int *error_found
,
595 u16 error_one
, error_next
;
597 error_one
= info
->dram_ferr
;
598 error_next
= info
->dram_nerr
;
600 /* decode and report errors */
601 if(error_one
& 0x0101) /* check first error correctable */
602 process_ce(mci
, error_one
, info
->dram_sec1_add
,
603 info
->dram_sec1_syndrome
, error_found
,
606 if(error_next
& 0x0101) /* check next error correctable */
607 process_ce(mci
, error_next
, info
->dram_sec2_add
,
608 info
->dram_sec2_syndrome
, error_found
,
611 if(error_one
& 0x4040)
612 process_ue_no_info_wr(mci
, error_found
, handle_error
);
614 if(error_next
& 0x4040)
615 process_ue_no_info_wr(mci
, error_found
, handle_error
);
617 if(error_one
& 0x2020)
618 process_ded_retry(mci
, error_one
, info
->dram_retr_add
,
619 error_found
, handle_error
);
621 if(error_next
& 0x2020)
622 process_ded_retry(mci
, error_next
, info
->dram_retr_add
,
623 error_found
, handle_error
);
625 if(error_one
& 0x0808)
626 process_threshold_ce(mci
, error_one
, error_found
,
629 if(error_next
& 0x0808)
630 process_threshold_ce(mci
, error_next
, error_found
,
633 if(error_one
& 0x0606)
634 process_ue(mci
, error_one
, info
->dram_ded_add
,
635 info
->dram_scrb_add
, error_found
, handle_error
);
637 if(error_next
& 0x0606)
638 process_ue(mci
, error_next
, info
->dram_ded_add
,
639 info
->dram_scrb_add
, error_found
, handle_error
);
642 static void e752x_get_error_info (struct mem_ctl_info
*mci
,
643 struct e752x_error_info
*info
)
646 struct e752x_pvt
*pvt
;
648 memset(info
, 0, sizeof(*info
));
649 pvt
= (struct e752x_pvt
*) mci
->pvt_info
;
651 pci_read_config_dword(dev
, E752X_FERR_GLOBAL
, &info
->ferr_global
);
653 if (info
->ferr_global
) {
654 pci_read_config_byte(dev
, E752X_HI_FERR
, &info
->hi_ferr
);
655 pci_read_config_word(dev
, E752X_SYSBUS_FERR
,
657 pci_read_config_byte(dev
, E752X_BUF_FERR
, &info
->buf_ferr
);
658 pci_read_config_word(dev
, E752X_DRAM_FERR
,
660 pci_read_config_dword(dev
, E752X_DRAM_SEC1_ADD
,
661 &info
->dram_sec1_add
);
662 pci_read_config_word(dev
, E752X_DRAM_SEC1_SYNDROME
,
663 &info
->dram_sec1_syndrome
);
664 pci_read_config_dword(dev
, E752X_DRAM_DED_ADD
,
665 &info
->dram_ded_add
);
666 pci_read_config_dword(dev
, E752X_DRAM_SCRB_ADD
,
667 &info
->dram_scrb_add
);
668 pci_read_config_dword(dev
, E752X_DRAM_RETR_ADD
,
669 &info
->dram_retr_add
);
671 if (info
->hi_ferr
& 0x7f)
672 pci_write_config_byte(dev
, E752X_HI_FERR
,
675 if (info
->sysbus_ferr
)
676 pci_write_config_word(dev
, E752X_SYSBUS_FERR
,
679 if (info
->buf_ferr
& 0x0f)
680 pci_write_config_byte(dev
, E752X_BUF_FERR
,
684 pci_write_bits16(pvt
->bridge_ck
, E752X_DRAM_FERR
,
685 info
->dram_ferr
, info
->dram_ferr
);
687 pci_write_config_dword(dev
, E752X_FERR_GLOBAL
,
691 pci_read_config_dword(dev
, E752X_NERR_GLOBAL
, &info
->nerr_global
);
693 if (info
->nerr_global
) {
694 pci_read_config_byte(dev
, E752X_HI_NERR
, &info
->hi_nerr
);
695 pci_read_config_word(dev
, E752X_SYSBUS_NERR
,
697 pci_read_config_byte(dev
, E752X_BUF_NERR
, &info
->buf_nerr
);
698 pci_read_config_word(dev
, E752X_DRAM_NERR
,
700 pci_read_config_dword(dev
, E752X_DRAM_SEC2_ADD
,
701 &info
->dram_sec2_add
);
702 pci_read_config_word(dev
, E752X_DRAM_SEC2_SYNDROME
,
703 &info
->dram_sec2_syndrome
);
705 if (info
->hi_nerr
& 0x7f)
706 pci_write_config_byte(dev
, E752X_HI_NERR
,
709 if (info
->sysbus_nerr
)
710 pci_write_config_word(dev
, E752X_SYSBUS_NERR
,
713 if (info
->buf_nerr
& 0x0f)
714 pci_write_config_byte(dev
, E752X_BUF_NERR
,
718 pci_write_bits16(pvt
->bridge_ck
, E752X_DRAM_NERR
,
719 info
->dram_nerr
, info
->dram_nerr
);
721 pci_write_config_dword(dev
, E752X_NERR_GLOBAL
,
726 static int e752x_process_error_info (struct mem_ctl_info
*mci
,
727 struct e752x_error_info
*info
, int handle_errors
)
733 error32
= (info
->ferr_global
>> 18) & 0x3ff;
734 stat32
= (info
->ferr_global
>> 4) & 0x7ff;
737 global_error(1, error32
, &error_found
, handle_errors
);
740 global_error(0, stat32
, &error_found
, handle_errors
);
742 error32
= (info
->nerr_global
>> 18) & 0x3ff;
743 stat32
= (info
->nerr_global
>> 4) & 0x7ff;
746 global_error(1, error32
, &error_found
, handle_errors
);
749 global_error(0, stat32
, &error_found
, handle_errors
);
751 e752x_check_hub_interface(info
, &error_found
, handle_errors
);
752 e752x_check_sysbus(info
, &error_found
, handle_errors
);
753 e752x_check_membuf(info
, &error_found
, handle_errors
);
754 e752x_check_dram(mci
, info
, &error_found
, handle_errors
);
758 static void e752x_check(struct mem_ctl_info
*mci
)
760 struct e752x_error_info info
;
762 debugf3("%s()\n", __func__
);
763 e752x_get_error_info(mci
, &info
);
764 e752x_process_error_info(mci
, &info
, 1);
767 /* Return 1 if dual channel mode is active. Else return 0. */
768 static inline int dual_channel_active(u16 ddrcsr
)
770 return (((ddrcsr
>> 12) & 3) == 3);
773 static void e752x_init_csrows(struct mem_ctl_info
*mci
, struct pci_dev
*pdev
,
776 struct csrow_info
*csrow
;
777 unsigned long last_cumul_size
;
778 int index
, mem_dev
, drc_chan
;
779 int drc_drbg
; /* DRB granularity 0=64mb, 1=128mb */
780 int drc_ddim
; /* DRAM Data Integrity Mode 0=none, 2=edac */
782 u32 dra
, drc
, cumul_size
;
784 pci_read_config_dword(pdev
, E752X_DRA
, &dra
);
785 pci_read_config_dword(pdev
, E752X_DRC
, &drc
);
786 drc_chan
= dual_channel_active(ddrcsr
);
787 drc_drbg
= drc_chan
+ 1; /* 128 in dual mode, 64 in single */
788 drc_ddim
= (drc
>> 20) & 0x3;
790 /* The dram row boundary (DRB) reg values are boundary address for
791 * each DRAM row with a granularity of 64 or 128MB (single/dual
792 * channel operation). DRB regs are cumulative; therefore DRB7 will
793 * contain the total memory contained in all eight rows.
795 for (last_cumul_size
= index
= 0; index
< mci
->nr_csrows
; index
++) {
796 /* mem_dev 0=x8, 1=x4 */
797 mem_dev
= (dra
>> (index
* 4 + 2)) & 0x3;
798 csrow
= &mci
->csrows
[index
];
800 mem_dev
= (mem_dev
== 2);
801 pci_read_config_byte(pdev
, E752X_DRB
+ index
, &value
);
802 /* convert a 128 or 64 MiB DRB to a page size. */
803 cumul_size
= value
<< (25 + drc_drbg
- PAGE_SHIFT
);
804 debugf3("%s(): (%d) cumul_size 0x%x\n", __func__
, index
,
806 if (cumul_size
== last_cumul_size
)
807 continue; /* not populated */
809 csrow
->first_page
= last_cumul_size
;
810 csrow
->last_page
= cumul_size
- 1;
811 csrow
->nr_pages
= cumul_size
- last_cumul_size
;
812 last_cumul_size
= cumul_size
;
813 csrow
->grain
= 1 << 12; /* 4KiB - resolution of CELOG */
814 csrow
->mtype
= MEM_RDDR
; /* only one type supported */
815 csrow
->dtype
= mem_dev
? DEV_X4
: DEV_X8
;
818 * if single channel or x8 devices then SECDED
819 * if dual channel and x4 then S4ECD4ED
822 if (drc_chan
&& mem_dev
) {
823 csrow
->edac_mode
= EDAC_S4ECD4ED
;
824 mci
->edac_cap
|= EDAC_FLAG_S4ECD4ED
;
826 csrow
->edac_mode
= EDAC_SECDED
;
827 mci
->edac_cap
|= EDAC_FLAG_SECDED
;
830 csrow
->edac_mode
= EDAC_NONE
;
834 static void e752x_init_mem_map_table(struct pci_dev
*pdev
,
835 struct e752x_pvt
*pvt
)
838 u8 value
, last
, row
, stat8
;
843 for (index
= 0; index
< 8; index
+= 2) {
844 pci_read_config_byte(pdev
, E752X_DRB
+ index
, &value
);
845 /* test if there is a dimm in this slot */
847 /* no dimm in the slot, so flag it as empty */
848 pvt
->map
[index
] = 0xff;
849 pvt
->map
[index
+ 1] = 0xff;
850 } else { /* there is a dimm in the slot */
851 pvt
->map
[index
] = row
;
854 /* test the next value to see if the dimm is double
857 pci_read_config_byte(pdev
, E752X_DRB
+ index
+ 1,
859 pvt
->map
[index
+ 1] = (value
== last
) ?
860 0xff : /* the dimm is single sided,
862 row
; /* this is a double sided dimm
863 to save the next row # */
869 /* set the map type. 1 = normal, 0 = reversed */
870 pci_read_config_byte(pdev
, E752X_DRM
, &stat8
);
871 pvt
->map_type
= ((stat8
& 0x0f) > ((stat8
>> 4) & 0x0f));
874 /* Return 0 on success or 1 on failure. */
875 static int e752x_get_devs(struct pci_dev
*pdev
, int dev_idx
,
876 struct e752x_pvt
*pvt
)
880 pvt
->bridge_ck
= pci_get_device(PCI_VENDOR_ID_INTEL
,
881 pvt
->dev_info
->err_dev
,
884 if (pvt
->bridge_ck
== NULL
)
885 pvt
->bridge_ck
= pci_scan_single_device(pdev
->bus
,
888 if (pvt
->bridge_ck
== NULL
) {
889 e752x_printk(KERN_ERR
, "error reporting device not found:"
890 "vendor %x device 0x%x (broken BIOS?)\n",
891 PCI_VENDOR_ID_INTEL
, e752x_devs
[dev_idx
].err_dev
);
895 dev
= pci_get_device(PCI_VENDOR_ID_INTEL
, e752x_devs
[dev_idx
].ctl_dev
,
902 pvt
->dev_d0f1
= pci_dev_get(pvt
->bridge_ck
);
907 pci_dev_put(pvt
->bridge_ck
);
911 static void e752x_init_error_reporting_regs(struct e752x_pvt
*pvt
)
916 /* Turn off error disable & SMI in case the BIOS turned it on */
917 pci_write_config_byte(dev
, E752X_HI_ERRMASK
, 0x00);
918 pci_write_config_byte(dev
, E752X_HI_SMICMD
, 0x00);
919 pci_write_config_word(dev
, E752X_SYSBUS_ERRMASK
, 0x00);
920 pci_write_config_word(dev
, E752X_SYSBUS_SMICMD
, 0x00);
921 pci_write_config_byte(dev
, E752X_BUF_ERRMASK
, 0x00);
922 pci_write_config_byte(dev
, E752X_BUF_SMICMD
, 0x00);
923 pci_write_config_byte(dev
, E752X_DRAM_ERRMASK
, 0x00);
924 pci_write_config_byte(dev
, E752X_DRAM_SMICMD
, 0x00);
927 static int e752x_probe1(struct pci_dev
*pdev
, int dev_idx
)
931 struct mem_ctl_info
*mci
;
932 struct e752x_pvt
*pvt
;
934 int drc_chan
; /* Number of channels 0=1chan,1=2chan */
935 struct e752x_error_info discard
;
937 debugf0("%s(): mci\n", __func__
);
938 debugf0("Starting Probe1\n");
940 /* check to see if device 0 function 1 is enabled; if it isn't, we
941 * assume the BIOS has reserved it for a reason and is expecting
942 * exclusive access, we take care not to violate that assumption and
944 pci_read_config_byte(pdev
, E752X_DEVPRES1
, &stat8
);
945 if (!force_function_unhide
&& !(stat8
& (1 << 5))) {
946 printk(KERN_INFO
"Contact your BIOS vendor to see if the "
947 "E752x error registers can be safely un-hidden\n");
951 pci_write_config_byte(pdev
, E752X_DEVPRES1
, stat8
);
953 pci_read_config_word(pdev
, E752X_DDRCSR
, &ddrcsr
);
954 /* FIXME: should check >>12 or 0xf, true for all? */
955 /* Dual channel = 1, Single channel = 0 */
956 drc_chan
= dual_channel_active(ddrcsr
);
958 mci
= edac_mc_alloc(sizeof(*pvt
), E752X_NR_CSROWS
, drc_chan
+ 1);
964 debugf3("%s(): init mci\n", __func__
);
965 mci
->mtype_cap
= MEM_FLAG_RDDR
;
966 mci
->edac_ctl_cap
= EDAC_FLAG_NONE
| EDAC_FLAG_SECDED
|
968 /* FIXME - what if different memory types are in different csrows? */
969 mci
->mod_name
= EDAC_MOD_STR
;
970 mci
->mod_ver
= E752X_REVISION
;
971 mci
->dev
= &pdev
->dev
;
973 debugf3("%s(): init pvt\n", __func__
);
974 pvt
= (struct e752x_pvt
*) mci
->pvt_info
;
975 pvt
->dev_info
= &e752x_devs
[dev_idx
];
976 pvt
->mc_symmetric
= ((ddrcsr
& 0x10) != 0);
978 if (e752x_get_devs(pdev
, dev_idx
, pvt
)) {
983 debugf3("%s(): more mci init\n", __func__
);
984 mci
->ctl_name
= pvt
->dev_info
->ctl_name
;
985 mci
->edac_check
= e752x_check
;
986 mci
->ctl_page_to_phys
= ctl_page_to_phys
;
988 e752x_init_csrows(mci
, pdev
, ddrcsr
);
989 e752x_init_mem_map_table(pdev
, pvt
);
991 /* set the map type. 1 = normal, 0 = reversed */
992 pci_read_config_byte(pdev
, E752X_DRM
, &stat8
);
993 pvt
->map_type
= ((stat8
& 0x0f) > ((stat8
>> 4) & 0x0f));
995 mci
->edac_cap
|= EDAC_FLAG_NONE
;
996 debugf3("%s(): tolm, remapbase, remaplimit\n", __func__
);
998 /* load the top of low memory, remap base, and remap limit vars */
999 pci_read_config_word(pdev
, E752X_TOLM
, &pci_data
);
1000 pvt
->tolm
= ((u32
) pci_data
) << 4;
1001 pci_read_config_word(pdev
, E752X_REMAPBASE
, &pci_data
);
1002 pvt
->remapbase
= ((u32
) pci_data
) << 14;
1003 pci_read_config_word(pdev
, E752X_REMAPLIMIT
, &pci_data
);
1004 pvt
->remaplimit
= ((u32
) pci_data
) << 14;
1005 e752x_printk(KERN_INFO
,
1006 "tolm = %x, remapbase = %x, remaplimit = %x\n", pvt
->tolm
,
1007 pvt
->remapbase
, pvt
->remaplimit
);
1009 /* Here we assume that we will never see multiple instances of this
1010 * type of memory controller. The ID is therefore hardcoded to 0.
1012 if (edac_mc_add_mc(mci
,0)) {
1013 debugf3("%s(): failed edac_mc_add_mc()\n", __func__
);
1017 e752x_init_error_reporting_regs(pvt
);
1018 e752x_get_error_info(mci
, &discard
); /* clear other MCH errors */
1020 /* get this far and it's successful */
1021 debugf3("%s(): success\n", __func__
);
1025 pci_dev_put(pvt
->dev_d0f0
);
1026 pci_dev_put(pvt
->dev_d0f1
);
1027 pci_dev_put(pvt
->bridge_ck
);
1033 /* returns count (>= 0), or negative on error */
1034 static int __devinit
e752x_init_one(struct pci_dev
*pdev
,
1035 const struct pci_device_id
*ent
)
1037 debugf0("%s()\n", __func__
);
1039 /* wake up and enable device */
1040 if(pci_enable_device(pdev
) < 0)
1043 return e752x_probe1(pdev
, ent
->driver_data
);
1046 static void __devexit
e752x_remove_one(struct pci_dev
*pdev
)
1048 struct mem_ctl_info
*mci
;
1049 struct e752x_pvt
*pvt
;
1051 debugf0("%s()\n", __func__
);
1053 if ((mci
= edac_mc_del_mc(&pdev
->dev
)) == NULL
)
1056 pvt
= (struct e752x_pvt
*) mci
->pvt_info
;
1057 pci_dev_put(pvt
->dev_d0f0
);
1058 pci_dev_put(pvt
->dev_d0f1
);
1059 pci_dev_put(pvt
->bridge_ck
);
1063 static const struct pci_device_id e752x_pci_tbl
[] __devinitdata
= {
1065 PCI_VEND_DEV(INTEL
, 7520_0
), PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
1069 PCI_VEND_DEV(INTEL
, 7525_0
), PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
1073 PCI_VEND_DEV(INTEL
, 7320_0
), PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
1078 } /* 0 terminated list. */
1081 MODULE_DEVICE_TABLE(pci
, e752x_pci_tbl
);
1083 static struct pci_driver e752x_driver
= {
1084 .name
= EDAC_MOD_STR
,
1085 .probe
= e752x_init_one
,
1086 .remove
= __devexit_p(e752x_remove_one
),
1087 .id_table
= e752x_pci_tbl
,
1090 static int __init
e752x_init(void)
1094 debugf3("%s()\n", __func__
);
1095 pci_rc
= pci_register_driver(&e752x_driver
);
1096 return (pci_rc
< 0) ? pci_rc
: 0;
1099 static void __exit
e752x_exit(void)
1101 debugf3("%s()\n", __func__
);
1102 pci_unregister_driver(&e752x_driver
);
1105 module_init(e752x_init
);
1106 module_exit(e752x_exit
);
1108 MODULE_LICENSE("GPL");
1109 MODULE_AUTHOR("Linux Networx (http://lnxi.com) Tom Zimmerman\n");
1110 MODULE_DESCRIPTION("MC support for Intel e752x memory controllers");
1112 module_param(force_function_unhide
, int, 0444);
1113 MODULE_PARM_DESC(force_function_unhide
, "if BIOS sets Dev0:Fun1 up as hidden:"
1114 " 1=force unhide and hope BIOS doesn't fight driver for Dev0:Fun1 access");