2 * Intel 5100 Memory Controllers kernel module
4 * This file may be distributed under the terms of the
5 * GNU General Public License.
7 * This module is based on the following document:
9 * Intel 5100X Chipset Memory Controller Hub (MCH) - Datasheet
10 * http://download.intel.com/design/chipsets/datashts/318378.pdf
12 * The intel 5100 has two independent channels. EDAC core currently
13 * can not reflect this configuration so instead the chip-select
14 * rows for each respective channel are laid out one after another,
15 * the first half belonging to channel 0, the second half belonging
18 * This driver is for DDR2 DIMMs, and it uses chip select to select among the
19 * several ranks. However, instead of showing memories as ranks, it outputs
20 * them as DIMM's. An internal table creates the association between ranks
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/pci.h>
26 #include <linux/pci_ids.h>
27 #include <linux/edac.h>
28 #include <linux/delay.h>
29 #include <linux/mmzone.h>
31 #include "edac_core.h"
33 /* register addresses */
35 /* device 16, func 1 */
36 #define I5100_MC 0x40 /* Memory Control Register */
37 #define I5100_MC_SCRBEN_MASK (1 << 7)
38 #define I5100_MC_SCRBDONE_MASK (1 << 4)
39 #define I5100_MS 0x44 /* Memory Status Register */
40 #define I5100_SPDDATA 0x48 /* Serial Presence Detect Status Reg */
41 #define I5100_SPDCMD 0x4c /* Serial Presence Detect Command Reg */
42 #define I5100_TOLM 0x6c /* Top of Low Memory */
43 #define I5100_MIR0 0x80 /* Memory Interleave Range 0 */
44 #define I5100_MIR1 0x84 /* Memory Interleave Range 1 */
45 #define I5100_AMIR_0 0x8c /* Adjusted Memory Interleave Range 0 */
46 #define I5100_AMIR_1 0x90 /* Adjusted Memory Interleave Range 1 */
47 #define I5100_FERR_NF_MEM 0xa0 /* MC First Non Fatal Errors */
48 #define I5100_FERR_NF_MEM_M16ERR_MASK (1 << 16)
49 #define I5100_FERR_NF_MEM_M15ERR_MASK (1 << 15)
50 #define I5100_FERR_NF_MEM_M14ERR_MASK (1 << 14)
51 #define I5100_FERR_NF_MEM_M12ERR_MASK (1 << 12)
52 #define I5100_FERR_NF_MEM_M11ERR_MASK (1 << 11)
53 #define I5100_FERR_NF_MEM_M10ERR_MASK (1 << 10)
54 #define I5100_FERR_NF_MEM_M6ERR_MASK (1 << 6)
55 #define I5100_FERR_NF_MEM_M5ERR_MASK (1 << 5)
56 #define I5100_FERR_NF_MEM_M4ERR_MASK (1 << 4)
57 #define I5100_FERR_NF_MEM_M1ERR_MASK (1 << 1)
58 #define I5100_FERR_NF_MEM_ANY_MASK \
59 (I5100_FERR_NF_MEM_M16ERR_MASK | \
60 I5100_FERR_NF_MEM_M15ERR_MASK | \
61 I5100_FERR_NF_MEM_M14ERR_MASK | \
62 I5100_FERR_NF_MEM_M12ERR_MASK | \
63 I5100_FERR_NF_MEM_M11ERR_MASK | \
64 I5100_FERR_NF_MEM_M10ERR_MASK | \
65 I5100_FERR_NF_MEM_M6ERR_MASK | \
66 I5100_FERR_NF_MEM_M5ERR_MASK | \
67 I5100_FERR_NF_MEM_M4ERR_MASK | \
68 I5100_FERR_NF_MEM_M1ERR_MASK)
69 #define I5100_NERR_NF_MEM 0xa4 /* MC Next Non-Fatal Errors */
70 #define I5100_EMASK_MEM 0xa8 /* MC Error Mask Register */
72 /* device 21 and 22, func 0 */
73 #define I5100_MTR_0 0x154 /* Memory Technology Registers 0-3 */
74 #define I5100_DMIR 0x15c /* DIMM Interleave Range */
75 #define I5100_VALIDLOG 0x18c /* Valid Log Markers */
76 #define I5100_NRECMEMA 0x190 /* Non-Recoverable Memory Error Log Reg A */
77 #define I5100_NRECMEMB 0x194 /* Non-Recoverable Memory Error Log Reg B */
78 #define I5100_REDMEMA 0x198 /* Recoverable Memory Data Error Log Reg A */
79 #define I5100_REDMEMB 0x19c /* Recoverable Memory Data Error Log Reg B */
80 #define I5100_RECMEMA 0x1a0 /* Recoverable Memory Error Log Reg A */
81 #define I5100_RECMEMB 0x1a4 /* Recoverable Memory Error Log Reg B */
82 #define I5100_MTR_4 0x1b0 /* Memory Technology Registers 4,5 */
84 /* bit field accessors */
86 static inline u32
i5100_mc_scrben(u32 mc
)
91 static inline u32
i5100_mc_errdeten(u32 mc
)
96 static inline u32
i5100_mc_scrbdone(u32 mc
)
101 static inline u16
i5100_spddata_rdo(u16 a
)
106 static inline u16
i5100_spddata_sbe(u16 a
)
111 static inline u16
i5100_spddata_busy(u16 a
)
116 static inline u16
i5100_spddata_data(u16 a
)
118 return a
& ((1 << 8) - 1);
121 static inline u32
i5100_spdcmd_create(u32 dti
, u32 ckovrd
, u32 sa
, u32 ba
,
124 return ((dti
& ((1 << 4) - 1)) << 28) |
125 ((ckovrd
& 1) << 27) |
126 ((sa
& ((1 << 3) - 1)) << 24) |
127 ((ba
& ((1 << 8) - 1)) << 16) |
128 ((data
& ((1 << 8) - 1)) << 8) |
132 static inline u16
i5100_tolm_tolm(u16 a
)
134 return a
>> 12 & ((1 << 4) - 1);
137 static inline u16
i5100_mir_limit(u16 a
)
139 return a
>> 4 & ((1 << 12) - 1);
142 static inline u16
i5100_mir_way1(u16 a
)
147 static inline u16
i5100_mir_way0(u16 a
)
152 static inline u32
i5100_ferr_nf_mem_chan_indx(u32 a
)
157 static inline u32
i5100_ferr_nf_mem_any(u32 a
)
159 return a
& I5100_FERR_NF_MEM_ANY_MASK
;
162 static inline u32
i5100_nerr_nf_mem_any(u32 a
)
164 return i5100_ferr_nf_mem_any(a
);
167 static inline u32
i5100_dmir_limit(u32 a
)
169 return a
>> 16 & ((1 << 11) - 1);
172 static inline u32
i5100_dmir_rank(u32 a
, u32 i
)
174 return a
>> (4 * i
) & ((1 << 2) - 1);
177 static inline u16
i5100_mtr_present(u16 a
)
182 static inline u16
i5100_mtr_ethrottle(u16 a
)
187 static inline u16
i5100_mtr_width(u16 a
)
192 static inline u16
i5100_mtr_numbank(u16 a
)
197 static inline u16
i5100_mtr_numrow(u16 a
)
199 return a
>> 2 & ((1 << 2) - 1);
202 static inline u16
i5100_mtr_numcol(u16 a
)
204 return a
& ((1 << 2) - 1);
208 static inline u32
i5100_validlog_redmemvalid(u32 a
)
213 static inline u32
i5100_validlog_recmemvalid(u32 a
)
218 static inline u32
i5100_validlog_nrecmemvalid(u32 a
)
223 static inline u32
i5100_nrecmema_merr(u32 a
)
225 return a
>> 15 & ((1 << 5) - 1);
228 static inline u32
i5100_nrecmema_bank(u32 a
)
230 return a
>> 12 & ((1 << 3) - 1);
233 static inline u32
i5100_nrecmema_rank(u32 a
)
235 return a
>> 8 & ((1 << 3) - 1);
238 static inline u32
i5100_nrecmema_dm_buf_id(u32 a
)
240 return a
& ((1 << 8) - 1);
243 static inline u32
i5100_nrecmemb_cas(u32 a
)
245 return a
>> 16 & ((1 << 13) - 1);
248 static inline u32
i5100_nrecmemb_ras(u32 a
)
250 return a
& ((1 << 16) - 1);
253 static inline u32
i5100_redmemb_ecc_locator(u32 a
)
255 return a
& ((1 << 18) - 1);
258 static inline u32
i5100_recmema_merr(u32 a
)
260 return i5100_nrecmema_merr(a
);
263 static inline u32
i5100_recmema_bank(u32 a
)
265 return i5100_nrecmema_bank(a
);
268 static inline u32
i5100_recmema_rank(u32 a
)
270 return i5100_nrecmema_rank(a
);
273 static inline u32
i5100_recmema_dm_buf_id(u32 a
)
275 return i5100_nrecmema_dm_buf_id(a
);
278 static inline u32
i5100_recmemb_cas(u32 a
)
280 return i5100_nrecmemb_cas(a
);
283 static inline u32
i5100_recmemb_ras(u32 a
)
285 return i5100_nrecmemb_ras(a
);
288 /* some generic limits */
289 #define I5100_MAX_RANKS_PER_CHAN 6
290 #define I5100_CHANNELS 2
291 #define I5100_MAX_RANKS_PER_DIMM 4
292 #define I5100_DIMM_ADDR_LINES (6 - 3) /* 64 bits / 8 bits per byte */
293 #define I5100_MAX_DIMM_SLOTS_PER_CHAN 4
294 #define I5100_MAX_RANK_INTERLEAVE 4
295 #define I5100_MAX_DMIRS 5
296 #define I5100_SCRUB_REFRESH_RATE (5 * 60 * HZ)
299 /* ranks on each dimm -- 0 maps to not present -- obtained via SPD */
300 int dimm_numrank
[I5100_CHANNELS
][I5100_MAX_DIMM_SLOTS_PER_CHAN
];
303 * mainboard chip select map -- maps i5100 chip selects to
304 * DIMM slot chip selects. In the case of only 4 ranks per
305 * channel, the mapping is fairly obvious but not unique.
306 * we map -1 -> NC and assume both channels use the same
310 int dimm_csmap
[I5100_MAX_DIMM_SLOTS_PER_CHAN
][I5100_MAX_RANKS_PER_DIMM
];
312 /* memory interleave range */
316 } mir
[I5100_CHANNELS
];
318 /* adjusted memory interleave range register */
319 unsigned amir
[I5100_CHANNELS
];
321 /* dimm interleave range */
323 unsigned rank
[I5100_MAX_RANK_INTERLEAVE
];
325 } dmir
[I5100_CHANNELS
][I5100_MAX_DMIRS
];
327 /* memory technology registers... */
329 unsigned present
; /* 0 or 1 */
330 unsigned ethrottle
; /* 0 or 1 */
331 unsigned width
; /* 4 or 8 bits */
332 unsigned numbank
; /* 2 or 3 lines */
333 unsigned numrow
; /* 13 .. 16 lines */
334 unsigned numcol
; /* 11 .. 12 lines */
335 } mtr
[I5100_CHANNELS
][I5100_MAX_RANKS_PER_CHAN
];
337 u64 tolm
; /* top of low memory in bytes */
338 unsigned ranksperchan
; /* number of ranks per channel */
340 struct pci_dev
*mc
; /* device 16 func 1 */
341 struct pci_dev
*ch0mm
; /* device 21 func 0 */
342 struct pci_dev
*ch1mm
; /* device 22 func 0 */
344 struct delayed_work i5100_scrubbing
;
348 /* map a rank/chan to a slot number on the mainboard */
349 static int i5100_rank_to_slot(const struct mem_ctl_info
*mci
,
352 const struct i5100_priv
*priv
= mci
->pvt_info
;
355 for (i
= 0; i
< I5100_MAX_DIMM_SLOTS_PER_CHAN
; i
++) {
357 const int numrank
= priv
->dimm_numrank
[chan
][i
];
359 for (j
= 0; j
< numrank
; j
++)
360 if (priv
->dimm_csmap
[i
][j
] == rank
)
367 static const char *i5100_err_msg(unsigned err
)
369 static const char *merrs
[] = {
371 "uncorrectable data ECC on replay", /* 1 */
374 "aliased uncorrectable demand data ECC", /* 4 */
375 "aliased uncorrectable spare-copy data ECC", /* 5 */
376 "aliased uncorrectable patrol data ECC", /* 6 */
380 "non-aliased uncorrectable demand data ECC", /* 10 */
381 "non-aliased uncorrectable spare-copy data ECC", /* 11 */
382 "non-aliased uncorrectable patrol data ECC", /* 12 */
384 "correctable demand data ECC", /* 14 */
385 "correctable spare-copy data ECC", /* 15 */
386 "correctable patrol data ECC", /* 16 */
388 "SPD protocol error", /* 18 */
390 "spare copy initiated", /* 20 */
391 "spare copy completed", /* 21 */
395 for (i
= 0; i
< ARRAY_SIZE(merrs
); i
++)
402 /* convert csrow index into a rank (per channel -- 0..5) */
403 static int i5100_csrow_to_rank(const struct mem_ctl_info
*mci
, int csrow
)
405 const struct i5100_priv
*priv
= mci
->pvt_info
;
407 return csrow
% priv
->ranksperchan
;
410 /* convert csrow index into a channel (0..1) */
411 static int i5100_csrow_to_chan(const struct mem_ctl_info
*mci
, int csrow
)
413 const struct i5100_priv
*priv
= mci
->pvt_info
;
415 return csrow
/ priv
->ranksperchan
;
418 static void i5100_handle_ce(struct mem_ctl_info
*mci
,
422 unsigned long syndrome
,
429 /* Form out message */
430 snprintf(detail
, sizeof(detail
),
431 "bank %u, cas %u, ras %u\n",
434 edac_mc_handle_error(HW_EVENT_ERR_CORRECTED
, mci
,
440 static void i5100_handle_ue(struct mem_ctl_info
*mci
,
444 unsigned long syndrome
,
451 /* Form out message */
452 snprintf(detail
, sizeof(detail
),
453 "bank %u, cas %u, ras %u\n",
456 edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED
, mci
,
462 static void i5100_read_log(struct mem_ctl_info
*mci
, int chan
,
465 struct i5100_priv
*priv
= mci
->pvt_info
;
466 struct pci_dev
*pdev
= (chan
) ? priv
->ch1mm
: priv
->ch0mm
;
469 unsigned syndrome
= 0;
470 unsigned ecc_loc
= 0;
477 pci_read_config_dword(pdev
, I5100_VALIDLOG
, &dw
);
479 if (i5100_validlog_redmemvalid(dw
)) {
480 pci_read_config_dword(pdev
, I5100_REDMEMA
, &dw2
);
482 pci_read_config_dword(pdev
, I5100_REDMEMB
, &dw2
);
483 ecc_loc
= i5100_redmemb_ecc_locator(dw2
);
486 if (i5100_validlog_recmemvalid(dw
)) {
489 pci_read_config_dword(pdev
, I5100_RECMEMA
, &dw2
);
490 merr
= i5100_recmema_merr(dw2
);
491 bank
= i5100_recmema_bank(dw2
);
492 rank
= i5100_recmema_rank(dw2
);
494 pci_read_config_dword(pdev
, I5100_RECMEMB
, &dw2
);
495 cas
= i5100_recmemb_cas(dw2
);
496 ras
= i5100_recmemb_ras(dw2
);
498 /* FIXME: not really sure if this is what merr is...
501 msg
= i5100_err_msg(ferr
);
503 msg
= i5100_err_msg(nerr
);
505 i5100_handle_ce(mci
, chan
, bank
, rank
, syndrome
, cas
, ras
, msg
);
508 if (i5100_validlog_nrecmemvalid(dw
)) {
511 pci_read_config_dword(pdev
, I5100_NRECMEMA
, &dw2
);
512 merr
= i5100_nrecmema_merr(dw2
);
513 bank
= i5100_nrecmema_bank(dw2
);
514 rank
= i5100_nrecmema_rank(dw2
);
516 pci_read_config_dword(pdev
, I5100_NRECMEMB
, &dw2
);
517 cas
= i5100_nrecmemb_cas(dw2
);
518 ras
= i5100_nrecmemb_ras(dw2
);
520 /* FIXME: not really sure if this is what merr is...
523 msg
= i5100_err_msg(ferr
);
525 msg
= i5100_err_msg(nerr
);
527 i5100_handle_ue(mci
, chan
, bank
, rank
, syndrome
, cas
, ras
, msg
);
530 pci_write_config_dword(pdev
, I5100_VALIDLOG
, dw
);
533 static void i5100_check_error(struct mem_ctl_info
*mci
)
535 struct i5100_priv
*priv
= mci
->pvt_info
;
538 pci_read_config_dword(priv
->mc
, I5100_FERR_NF_MEM
, &dw
);
539 if (i5100_ferr_nf_mem_any(dw
)) {
541 pci_read_config_dword(priv
->mc
, I5100_NERR_NF_MEM
, &dw2
);
543 i5100_read_log(mci
, i5100_ferr_nf_mem_chan_indx(dw
),
544 i5100_ferr_nf_mem_any(dw
),
545 i5100_nerr_nf_mem_any(dw2
));
547 pci_write_config_dword(priv
->mc
, I5100_NERR_NF_MEM
, dw2
);
549 pci_write_config_dword(priv
->mc
, I5100_FERR_NF_MEM
, dw
);
552 /* The i5100 chipset will scrub the entire memory once, then
553 * set a done bit. Continuous scrubbing is achieved by enqueing
554 * delayed work to a workqueue, checking every few minutes if
555 * the scrubbing has completed and if so reinitiating it.
558 static void i5100_refresh_scrubbing(struct work_struct
*work
)
560 struct delayed_work
*i5100_scrubbing
= container_of(work
,
563 struct i5100_priv
*priv
= container_of(i5100_scrubbing
,
568 pci_read_config_dword(priv
->mc
, I5100_MC
, &dw
);
570 if (priv
->scrub_enable
) {
572 pci_read_config_dword(priv
->mc
, I5100_MC
, &dw
);
574 if (i5100_mc_scrbdone(dw
)) {
575 dw
|= I5100_MC_SCRBEN_MASK
;
576 pci_write_config_dword(priv
->mc
, I5100_MC
, dw
);
577 pci_read_config_dword(priv
->mc
, I5100_MC
, &dw
);
580 schedule_delayed_work(&(priv
->i5100_scrubbing
),
581 I5100_SCRUB_REFRESH_RATE
);
585 * The bandwidth is based on experimentation, feel free to refine it.
587 static int i5100_set_scrub_rate(struct mem_ctl_info
*mci
, u32 bandwidth
)
589 struct i5100_priv
*priv
= mci
->pvt_info
;
592 pci_read_config_dword(priv
->mc
, I5100_MC
, &dw
);
594 priv
->scrub_enable
= 1;
595 dw
|= I5100_MC_SCRBEN_MASK
;
596 schedule_delayed_work(&(priv
->i5100_scrubbing
),
597 I5100_SCRUB_REFRESH_RATE
);
599 priv
->scrub_enable
= 0;
600 dw
&= ~I5100_MC_SCRBEN_MASK
;
601 cancel_delayed_work(&(priv
->i5100_scrubbing
));
603 pci_write_config_dword(priv
->mc
, I5100_MC
, dw
);
605 pci_read_config_dword(priv
->mc
, I5100_MC
, &dw
);
607 bandwidth
= 5900000 * i5100_mc_scrben(dw
);
612 static int i5100_get_scrub_rate(struct mem_ctl_info
*mci
)
614 struct i5100_priv
*priv
= mci
->pvt_info
;
617 pci_read_config_dword(priv
->mc
, I5100_MC
, &dw
);
619 return 5900000 * i5100_mc_scrben(dw
);
622 static struct pci_dev
*pci_get_device_func(unsigned vendor
,
626 struct pci_dev
*ret
= NULL
;
629 ret
= pci_get_device(vendor
, device
, ret
);
634 if (PCI_FUNC(ret
->devfn
) == func
)
641 static unsigned long __devinit
i5100_npages(struct mem_ctl_info
*mci
,
644 struct i5100_priv
*priv
= mci
->pvt_info
;
645 const unsigned chan_rank
= i5100_csrow_to_rank(mci
, csrow
);
646 const unsigned chan
= i5100_csrow_to_chan(mci
, csrow
);
650 if (!priv
->mtr
[chan
][chan_rank
].present
)
654 I5100_DIMM_ADDR_LINES
+
655 priv
->mtr
[chan
][chan_rank
].numcol
+
656 priv
->mtr
[chan
][chan_rank
].numrow
+
657 priv
->mtr
[chan
][chan_rank
].numbank
;
659 return (unsigned long)
660 ((unsigned long long) (1ULL << addr_lines
) / PAGE_SIZE
);
663 static void __devinit
i5100_init_mtr(struct mem_ctl_info
*mci
)
665 struct i5100_priv
*priv
= mci
->pvt_info
;
666 struct pci_dev
*mms
[2] = { priv
->ch0mm
, priv
->ch1mm
};
669 for (i
= 0; i
< I5100_CHANNELS
; i
++) {
671 struct pci_dev
*pdev
= mms
[i
];
673 for (j
= 0; j
< I5100_MAX_RANKS_PER_CHAN
; j
++) {
674 const unsigned addr
=
675 (j
< 4) ? I5100_MTR_0
+ j
* 2 :
676 I5100_MTR_4
+ (j
- 4) * 2;
679 pci_read_config_word(pdev
, addr
, &w
);
681 priv
->mtr
[i
][j
].present
= i5100_mtr_present(w
);
682 priv
->mtr
[i
][j
].ethrottle
= i5100_mtr_ethrottle(w
);
683 priv
->mtr
[i
][j
].width
= 4 + 4 * i5100_mtr_width(w
);
684 priv
->mtr
[i
][j
].numbank
= 2 + i5100_mtr_numbank(w
);
685 priv
->mtr
[i
][j
].numrow
= 13 + i5100_mtr_numrow(w
);
686 priv
->mtr
[i
][j
].numcol
= 10 + i5100_mtr_numcol(w
);
692 * FIXME: make this into a real i2c adapter (so that dimm-decode
695 static int i5100_read_spd_byte(const struct mem_ctl_info
*mci
,
696 u8 ch
, u8 slot
, u8 addr
, u8
*byte
)
698 struct i5100_priv
*priv
= mci
->pvt_info
;
702 pci_read_config_word(priv
->mc
, I5100_SPDDATA
, &w
);
703 if (i5100_spddata_busy(w
))
706 pci_write_config_dword(priv
->mc
, I5100_SPDCMD
,
707 i5100_spdcmd_create(0xa, 1, ch
* 4 + slot
, addr
,
710 /* wait up to 100ms */
711 et
= jiffies
+ HZ
/ 10;
714 pci_read_config_word(priv
->mc
, I5100_SPDDATA
, &w
);
715 if (!i5100_spddata_busy(w
))
720 if (!i5100_spddata_rdo(w
) || i5100_spddata_sbe(w
))
723 *byte
= i5100_spddata_data(w
);
729 * fill dimm chip select map
732 * o not the only way to may chip selects to dimm slots
733 * o investigate if there is some way to obtain this map from the bios
735 static void __devinit
i5100_init_dimm_csmap(struct mem_ctl_info
*mci
)
737 struct i5100_priv
*priv
= mci
->pvt_info
;
740 for (i
= 0; i
< I5100_MAX_DIMM_SLOTS_PER_CHAN
; i
++) {
743 for (j
= 0; j
< I5100_MAX_RANKS_PER_DIMM
; j
++)
744 priv
->dimm_csmap
[i
][j
] = -1; /* default NC */
747 /* only 2 chip selects per slot... */
748 if (priv
->ranksperchan
== 4) {
749 priv
->dimm_csmap
[0][0] = 0;
750 priv
->dimm_csmap
[0][1] = 3;
751 priv
->dimm_csmap
[1][0] = 1;
752 priv
->dimm_csmap
[1][1] = 2;
753 priv
->dimm_csmap
[2][0] = 2;
754 priv
->dimm_csmap
[3][0] = 3;
756 priv
->dimm_csmap
[0][0] = 0;
757 priv
->dimm_csmap
[0][1] = 1;
758 priv
->dimm_csmap
[1][0] = 2;
759 priv
->dimm_csmap
[1][1] = 3;
760 priv
->dimm_csmap
[2][0] = 4;
761 priv
->dimm_csmap
[2][1] = 5;
765 static void __devinit
i5100_init_dimm_layout(struct pci_dev
*pdev
,
766 struct mem_ctl_info
*mci
)
768 struct i5100_priv
*priv
= mci
->pvt_info
;
771 for (i
= 0; i
< I5100_CHANNELS
; i
++) {
774 for (j
= 0; j
< I5100_MAX_DIMM_SLOTS_PER_CHAN
; j
++) {
777 if (i5100_read_spd_byte(mci
, i
, j
, 5, &rank
) < 0)
778 priv
->dimm_numrank
[i
][j
] = 0;
780 priv
->dimm_numrank
[i
][j
] = (rank
& 3) + 1;
784 i5100_init_dimm_csmap(mci
);
787 static void __devinit
i5100_init_interleaving(struct pci_dev
*pdev
,
788 struct mem_ctl_info
*mci
)
792 struct i5100_priv
*priv
= mci
->pvt_info
;
793 struct pci_dev
*mms
[2] = { priv
->ch0mm
, priv
->ch1mm
};
796 pci_read_config_word(pdev
, I5100_TOLM
, &w
);
797 priv
->tolm
= (u64
) i5100_tolm_tolm(w
) * 256 * 1024 * 1024;
799 pci_read_config_word(pdev
, I5100_MIR0
, &w
);
800 priv
->mir
[0].limit
= (u64
) i5100_mir_limit(w
) << 28;
801 priv
->mir
[0].way
[1] = i5100_mir_way1(w
);
802 priv
->mir
[0].way
[0] = i5100_mir_way0(w
);
804 pci_read_config_word(pdev
, I5100_MIR1
, &w
);
805 priv
->mir
[1].limit
= (u64
) i5100_mir_limit(w
) << 28;
806 priv
->mir
[1].way
[1] = i5100_mir_way1(w
);
807 priv
->mir
[1].way
[0] = i5100_mir_way0(w
);
809 pci_read_config_word(pdev
, I5100_AMIR_0
, &w
);
811 pci_read_config_word(pdev
, I5100_AMIR_1
, &w
);
814 for (i
= 0; i
< I5100_CHANNELS
; i
++) {
817 for (j
= 0; j
< 5; j
++) {
820 pci_read_config_dword(mms
[i
], I5100_DMIR
+ j
* 4, &dw
);
822 priv
->dmir
[i
][j
].limit
=
823 (u64
) i5100_dmir_limit(dw
) << 28;
824 for (k
= 0; k
< I5100_MAX_RANKS_PER_DIMM
; k
++)
825 priv
->dmir
[i
][j
].rank
[k
] =
826 i5100_dmir_rank(dw
, k
);
833 static void __devinit
i5100_init_csrows(struct mem_ctl_info
*mci
)
836 struct i5100_priv
*priv
= mci
->pvt_info
;
838 for (i
= 0; i
< mci
->tot_dimms
; i
++) {
839 struct dimm_info
*dimm
;
840 const unsigned long npages
= i5100_npages(mci
, i
);
841 const unsigned chan
= i5100_csrow_to_chan(mci
, i
);
842 const unsigned rank
= i5100_csrow_to_rank(mci
, i
);
847 dimm
= EDAC_DIMM_PTR(mci
->layers
, mci
->dimms
, mci
->n_layers
,
850 dimm
->nr_pages
= npages
;
853 dimm
->dtype
= (priv
->mtr
[chan
][rank
].width
== 4) ?
855 dimm
->mtype
= MEM_RDDR2
;
856 dimm
->edac_mode
= EDAC_SECDED
;
857 snprintf(dimm
->label
, sizeof(dimm
->label
),
859 i5100_rank_to_slot(mci
, chan
, rank
));
862 debugf2("dimm channel %d, rank %d, size %ld\n",
863 chan
, rank
, (long)PAGES_TO_MiB(npages
));
867 static int __devinit
i5100_init_one(struct pci_dev
*pdev
,
868 const struct pci_device_id
*id
)
871 struct mem_ctl_info
*mci
;
872 struct edac_mc_layer layers
[2];
873 struct i5100_priv
*priv
;
874 struct pci_dev
*ch0mm
, *ch1mm
;
879 if (PCI_FUNC(pdev
->devfn
) != 1)
882 rc
= pci_enable_device(pdev
);
889 pci_read_config_dword(pdev
, I5100_MC
, &dw
);
890 if (!i5100_mc_errdeten(dw
)) {
891 printk(KERN_INFO
"i5100_edac: ECC not enabled.\n");
896 /* figure out how many ranks, from strapped state of 48GB_Mode input */
897 pci_read_config_dword(pdev
, I5100_MS
, &dw
);
898 ranksperch
= !!(dw
& (1 << 8)) * 2 + 4;
900 /* enable error reporting... */
901 pci_read_config_dword(pdev
, I5100_EMASK_MEM
, &dw
);
902 dw
&= ~I5100_FERR_NF_MEM_ANY_MASK
;
903 pci_write_config_dword(pdev
, I5100_EMASK_MEM
, dw
);
905 /* device 21, func 0, Channel 0 Memory Map, Error Flag/Mask, etc... */
906 ch0mm
= pci_get_device_func(PCI_VENDOR_ID_INTEL
,
907 PCI_DEVICE_ID_INTEL_5100_21
, 0);
913 rc
= pci_enable_device(ch0mm
);
919 /* device 22, func 0, Channel 1 Memory Map, Error Flag/Mask, etc... */
920 ch1mm
= pci_get_device_func(PCI_VENDOR_ID_INTEL
,
921 PCI_DEVICE_ID_INTEL_5100_22
, 0);
924 goto bail_disable_ch0
;
927 rc
= pci_enable_device(ch1mm
);
933 layers
[0].type
= EDAC_MC_LAYER_CHANNEL
;
935 layers
[0].is_virt_csrow
= false;
936 layers
[1].type
= EDAC_MC_LAYER_SLOT
;
937 layers
[1].size
= ranksperch
;
938 layers
[1].is_virt_csrow
= true;
939 mci
= edac_mc_alloc(0, ARRAY_SIZE(layers
), layers
,
943 goto bail_disable_ch1
;
946 mci
->dev
= &pdev
->dev
;
948 priv
= mci
->pvt_info
;
949 priv
->ranksperchan
= ranksperch
;
954 INIT_DELAYED_WORK(&(priv
->i5100_scrubbing
), i5100_refresh_scrubbing
);
956 /* If scrubbing was already enabled by the bios, start maintaining it */
957 pci_read_config_dword(pdev
, I5100_MC
, &dw
);
958 if (i5100_mc_scrben(dw
)) {
959 priv
->scrub_enable
= 1;
960 schedule_delayed_work(&(priv
->i5100_scrubbing
),
961 I5100_SCRUB_REFRESH_RATE
);
964 i5100_init_dimm_layout(pdev
, mci
);
965 i5100_init_interleaving(pdev
, mci
);
967 mci
->mtype_cap
= MEM_FLAG_FB_DDR2
;
968 mci
->edac_ctl_cap
= EDAC_FLAG_SECDED
;
969 mci
->edac_cap
= EDAC_FLAG_SECDED
;
970 mci
->mod_name
= "i5100_edac.c";
971 mci
->mod_ver
= "not versioned";
972 mci
->ctl_name
= "i5100";
973 mci
->dev_name
= pci_name(pdev
);
974 mci
->ctl_page_to_phys
= NULL
;
976 mci
->edac_check
= i5100_check_error
;
977 mci
->set_sdram_scrub_rate
= i5100_set_scrub_rate
;
978 mci
->get_sdram_scrub_rate
= i5100_get_scrub_rate
;
980 i5100_init_csrows(mci
);
982 /* this strange construction seems to be in every driver, dunno why */
983 switch (edac_op_state
) {
984 case EDAC_OPSTATE_POLL
:
985 case EDAC_OPSTATE_NMI
:
988 edac_op_state
= EDAC_OPSTATE_POLL
;
992 if (edac_mc_add_mc(mci
)) {
1000 priv
->scrub_enable
= 0;
1001 cancel_delayed_work_sync(&(priv
->i5100_scrubbing
));
1005 pci_disable_device(ch1mm
);
1011 pci_disable_device(ch0mm
);
1017 pci_disable_device(pdev
);
1023 static void __devexit
i5100_remove_one(struct pci_dev
*pdev
)
1025 struct mem_ctl_info
*mci
;
1026 struct i5100_priv
*priv
;
1028 mci
= edac_mc_del_mc(&pdev
->dev
);
1033 priv
= mci
->pvt_info
;
1035 priv
->scrub_enable
= 0;
1036 cancel_delayed_work_sync(&(priv
->i5100_scrubbing
));
1038 pci_disable_device(pdev
);
1039 pci_disable_device(priv
->ch0mm
);
1040 pci_disable_device(priv
->ch1mm
);
1041 pci_dev_put(priv
->ch0mm
);
1042 pci_dev_put(priv
->ch1mm
);
1047 static DEFINE_PCI_DEVICE_TABLE(i5100_pci_tbl
) = {
1048 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
1049 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_5100_16
) },
1052 MODULE_DEVICE_TABLE(pci
, i5100_pci_tbl
);
1054 static struct pci_driver i5100_driver
= {
1055 .name
= KBUILD_BASENAME
,
1056 .probe
= i5100_init_one
,
1057 .remove
= __devexit_p(i5100_remove_one
),
1058 .id_table
= i5100_pci_tbl
,
1061 static int __init
i5100_init(void)
1065 pci_rc
= pci_register_driver(&i5100_driver
);
1067 return (pci_rc
< 0) ? pci_rc
: 0;
1070 static void __exit
i5100_exit(void)
1072 pci_unregister_driver(&i5100_driver
);
1075 module_init(i5100_init
);
1076 module_exit(i5100_exit
);
1078 MODULE_LICENSE("GPL");
1080 ("Arthur Jones <ajones@riverbed.com>");
1081 MODULE_DESCRIPTION("MC Driver for Intel I5100 memory controllers");