blob: d190104081ca1b5d568413b4a2747627154c6bbe [file] [log] [blame]
Tim Small5a2c6752007-07-19 01:49:42 -07001/*
2 * Intel 82443BX/GX (440BX/GX chipset) Memory Controller EDAC kernel
3 * module (C) 2006 Tim Small
4 *
5 * This file may be distributed under the terms of the GNU General
6 * Public License.
7 *
8 * Written by Tim Small <tim@buttersideup.com>, based on work by Linux
9 * Networx, Thayne Harbaugh, Dan Hollis <goemon at anime dot net> and
10 * others.
11 *
12 * 440GX fix by Jason Uhlenkott <juhlenko@akamai.com>.
13 *
14 * Written with reference to 82443BX Host Bridge Datasheet:
15 * http://www.intel.com/design/chipsets/440/documentation.htm
16 * references to this document given in [].
17 *
18 * This module doesn't support the 440LX, but it may be possible to
19 * make it do so (the 440LX's register definitions are different, but
20 * not completely so - I haven't studied them in enough detail to know
21 * how easy this would be).
22 */
23
24#include <linux/module.h>
25#include <linux/init.h>
26
27#include <linux/pci.h>
28#include <linux/pci_ids.h>
29
30#include <linux/slab.h>
31
Douglas Thompson20bcb7a2007-07-19 01:49:47 -070032#include "edac_core.h"
Tim Small5a2c6752007-07-19 01:49:42 -070033
34#define I82443_REVISION "0.1"
35
36#define EDAC_MOD_STR "i82443bxgx_edac"
37
Tim Small5a2c6752007-07-19 01:49:42 -070038/* The 82443BX supports SDRAM, or EDO (EDO for mobile only), "Memory
39 * Size: 8 MB to 512 MB (1GB with Registered DIMMs) with eight memory
40 * rows" "The 82443BX supports multiple-bit error detection and
41 * single-bit error correction when ECC mode is enabled and
42 * single/multi-bit error detection when correction is disabled.
43 * During writes to the DRAM, the 82443BX generates ECC for the data
44 * on a QWord basis. Partial QWord writes require a read-modify-write
45 * cycle when ECC is enabled."
46*/
47
48/* "Additionally, the 82443BX ensures that the data is corrected in
49 * main memory so that accumulation of errors is prevented. Another
50 * error within the same QWord would result in a double-bit error
51 * which is unrecoverable. This is known as hardware scrubbing since
52 * it requires no software intervention to correct the data in memory."
53 */
54
55/* [Also see page 100 (section 4.3), "DRAM Interface"]
56 * [Also see page 112 (section 4.6.1.4), ECC]
57 */
58
59#define I82443BXGX_NR_CSROWS 8
60#define I82443BXGX_NR_CHANS 1
61#define I82443BXGX_NR_DIMMS 4
62
Tim Small5a2c6752007-07-19 01:49:42 -070063/* 82443 PCI Device 0 */
Douglas Thompson11116602007-07-19 01:50:07 -070064#define I82443BXGX_NBXCFG 0x50 /* 32bit register starting at this PCI
65 * config space offset */
66#define I82443BXGX_NBXCFG_OFFSET_NON_ECCROW 24 /* Array of bits, zero if
67 * row is non-ECC */
68#define I82443BXGX_NBXCFG_OFFSET_DRAM_FREQ 12 /* 2 bits,00=100MHz,10=66 MHz */
Tim Small5a2c6752007-07-19 01:49:42 -070069
Douglas Thompson11116602007-07-19 01:50:07 -070070#define I82443BXGX_NBXCFG_OFFSET_DRAM_INTEGRITY 7 /* 2 bits: */
71#define I82443BXGX_NBXCFG_INTEGRITY_NONE 0x0 /* 00 = Non-ECC */
72#define I82443BXGX_NBXCFG_INTEGRITY_EC 0x1 /* 01 = EC (only) */
73#define I82443BXGX_NBXCFG_INTEGRITY_ECC 0x2 /* 10 = ECC */
74#define I82443BXGX_NBXCFG_INTEGRITY_SCRUB 0x3 /* 11 = ECC + HW Scrub */
Tim Small5a2c6752007-07-19 01:49:42 -070075
76#define I82443BXGX_NBXCFG_OFFSET_ECC_DIAG_ENABLE 6
77
Tim Small5a2c6752007-07-19 01:49:42 -070078/* 82443 PCI Device 0 */
Douglas Thompson11116602007-07-19 01:50:07 -070079#define I82443BXGX_EAP 0x80 /* 32bit register starting at this PCI
80 * config space offset, Error Address
81 * Pointer Register */
82#define I82443BXGX_EAP_OFFSET_EAP 12 /* High 20 bits of error address */
83#define I82443BXGX_EAP_OFFSET_MBE BIT(1) /* Err at EAP was multi-bit (W1TC) */
84#define I82443BXGX_EAP_OFFSET_SBE BIT(0) /* Err at EAP was single-bit (W1TC) */
Tim Small5a2c6752007-07-19 01:49:42 -070085
Douglas Thompson11116602007-07-19 01:50:07 -070086#define I82443BXGX_ERRCMD 0x90 /* 8bit register starting at this PCI
Tim Small5a2c6752007-07-19 01:49:42 -070087 * config space offset. */
Douglas Thompson11116602007-07-19 01:50:07 -070088#define I82443BXGX_ERRCMD_OFFSET_SERR_ON_MBE BIT(1) /* 1 = enable */
89#define I82443BXGX_ERRCMD_OFFSET_SERR_ON_SBE BIT(0) /* 1 = enable */
Tim Small5a2c6752007-07-19 01:49:42 -070090
Douglas Thompson11116602007-07-19 01:50:07 -070091#define I82443BXGX_ERRSTS 0x91 /* 16bit register starting at this PCI
Tim Small5a2c6752007-07-19 01:49:42 -070092 * config space offset. */
Douglas Thompson11116602007-07-19 01:50:07 -070093#define I82443BXGX_ERRSTS_OFFSET_MBFRE 5 /* 3 bits - first err row multibit */
94#define I82443BXGX_ERRSTS_OFFSET_MEF BIT(4) /* 1 = MBE occurred */
95#define I82443BXGX_ERRSTS_OFFSET_SBFRE 1 /* 3 bits - first err row singlebit */
96#define I82443BXGX_ERRSTS_OFFSET_SEF BIT(0) /* 1 = SBE occurred */
Tim Small5a2c6752007-07-19 01:49:42 -070097
Douglas Thompson11116602007-07-19 01:50:07 -070098#define I82443BXGX_DRAMC 0x57 /* 8bit register starting at this PCI
99 * config space offset. */
100#define I82443BXGX_DRAMC_OFFSET_DT 3 /* 2 bits, DRAM Type */
101#define I82443BXGX_DRAMC_DRAM_IS_EDO 0 /* 00 = EDO */
Tim Small5a2c6752007-07-19 01:49:42 -0700102#define I82443BXGX_DRAMC_DRAM_IS_SDRAM 1 /* 01 = SDRAM */
Douglas Thompson11116602007-07-19 01:50:07 -0700103#define I82443BXGX_DRAMC_DRAM_IS_RSDRAM 2 /* 10 = Registered SDRAM */
Tim Small5a2c6752007-07-19 01:49:42 -0700104
Douglas Thompson11116602007-07-19 01:50:07 -0700105#define I82443BXGX_DRB 0x60 /* 8x 8bit registers starting at this PCI
106 * config space offset. */
Tim Small5a2c6752007-07-19 01:49:42 -0700107
108/* FIXME - don't poll when ECC disabled? */
109
Tim Small5a2c6752007-07-19 01:49:42 -0700110struct i82443bxgx_edacmc_error_info {
111 u32 eap;
112};
113
Dave Jiang456a2f92007-07-19 01:50:10 -0700114static struct edac_pci_ctl_info *i82443bxgx_pci;
115
Douglas Thompson11116602007-07-19 01:50:07 -0700116static void i82443bxgx_edacmc_get_error_info(struct mem_ctl_info *mci,
117 struct i82443bxgx_edacmc_error_info
118 *info)
Tim Small5a2c6752007-07-19 01:49:42 -0700119{
120 struct pci_dev *pdev;
121 pdev = to_pci_dev(mci->dev);
122 pci_read_config_dword(pdev, I82443BXGX_EAP, &info->eap);
123 if (info->eap & I82443BXGX_EAP_OFFSET_SBE)
124 /* Clear error to allow next error to be reported [p.61] */
125 pci_write_bits32(pdev, I82443BXGX_EAP,
126 I82443BXGX_EAP_OFFSET_SBE,
127 I82443BXGX_EAP_OFFSET_SBE);
128
129 if (info->eap & I82443BXGX_EAP_OFFSET_MBE)
130 /* Clear error to allow next error to be reported [p.61] */
131 pci_write_bits32(pdev, I82443BXGX_EAP,
132 I82443BXGX_EAP_OFFSET_MBE,
133 I82443BXGX_EAP_OFFSET_MBE);
134}
135
Douglas Thompson11116602007-07-19 01:50:07 -0700136static int i82443bxgx_edacmc_process_error_info(struct mem_ctl_info *mci,
137 struct
138 i82443bxgx_edacmc_error_info
139 *info, int handle_errors)
Tim Small5a2c6752007-07-19 01:49:42 -0700140{
141 int error_found = 0;
142 u32 eapaddr, page, pageoffset;
143
144 /* bits 30:12 hold the 4kb block in which the error occurred
145 * [p.61] */
146 eapaddr = (info->eap & 0xfffff000);
147 page = eapaddr >> PAGE_SHIFT;
148 pageoffset = eapaddr - (page << PAGE_SHIFT);
149
Douglas Thompson11116602007-07-19 01:50:07 -0700150 if (info->eap & I82443BXGX_EAP_OFFSET_SBE) {
Tim Small5a2c6752007-07-19 01:49:42 -0700151 error_found = 1;
152 if (handle_errors)
Douglas Thompson11116602007-07-19 01:50:07 -0700153 edac_mc_handle_ce(mci, page, pageoffset,
154 /* 440BX/GX don't make syndrome information available */
155 0, edac_mc_find_csrow_by_page(mci, page), 0, /* channel */
156 mci->ctl_name);
Tim Small5a2c6752007-07-19 01:49:42 -0700157 }
158
Douglas Thompson11116602007-07-19 01:50:07 -0700159 if (info->eap & I82443BXGX_EAP_OFFSET_MBE) {
Tim Small5a2c6752007-07-19 01:49:42 -0700160 error_found = 1;
161 if (handle_errors)
Douglas Thompson11116602007-07-19 01:50:07 -0700162 edac_mc_handle_ue(mci, page, pageoffset,
163 edac_mc_find_csrow_by_page(mci, page),
164 mci->ctl_name);
Tim Small5a2c6752007-07-19 01:49:42 -0700165 }
166
167 return error_found;
168}
169
Tim Small5a2c6752007-07-19 01:49:42 -0700170static void i82443bxgx_edacmc_check(struct mem_ctl_info *mci)
171{
172 struct i82443bxgx_edacmc_error_info info;
173
174 debugf1("MC%d: " __FILE__ ": %s()\n", mci->mc_idx, __func__);
175 i82443bxgx_edacmc_get_error_info(mci, &info);
176 i82443bxgx_edacmc_process_error_info(mci, &info, 1);
177}
178
Tim Small5a2c6752007-07-19 01:49:42 -0700179static void i82443bxgx_init_csrows(struct mem_ctl_info *mci,
Douglas Thompson11116602007-07-19 01:50:07 -0700180 struct pci_dev *pdev,
181 enum edac_type edac_mode,
182 enum mem_type mtype)
Tim Small5a2c6752007-07-19 01:49:42 -0700183{
184 struct csrow_info *csrow;
185 int index;
186 u8 drbar, dramc;
187 u32 row_base, row_high_limit, row_high_limit_last;
188
189 pci_read_config_byte(pdev, I82443BXGX_DRAMC, &dramc);
190 row_high_limit_last = 0;
191 for (index = 0; index < mci->nr_csrows; index++) {
192 csrow = &mci->csrows[index];
193 pci_read_config_byte(pdev, I82443BXGX_DRB + index, &drbar);
194 debugf1("MC%d: " __FILE__ ": %s() Row=%d DRB = %#0x\n",
195 mci->mc_idx, __func__, index, drbar);
196 row_high_limit = ((u32) drbar << 23);
197 /* find the DRAM Chip Select Base address and mask */
198 debugf1("MC%d: " __FILE__ ": %s() Row=%d, "
199 "Boundry Address=%#0x, Last = %#0x \n",
200 mci->mc_idx, __func__, index, row_high_limit,
201 row_high_limit_last);
202
203 /* 440GX goes to 2GB, represented with a DRB of 0. */
204 if (row_high_limit_last && !row_high_limit)
205 row_high_limit = 1UL << 31;
206
207 /* This row is empty [p.49] */
208 if (row_high_limit == row_high_limit_last)
209 continue;
210 row_base = row_high_limit_last;
211 csrow->first_page = row_base >> PAGE_SHIFT;
212 csrow->last_page = (row_high_limit >> PAGE_SHIFT) - 1;
213 csrow->nr_pages = csrow->last_page - csrow->first_page + 1;
214 /* EAP reports in 4kilobyte granularity [61] */
215 csrow->grain = 1 << 12;
216 csrow->mtype = mtype;
217 /* I don't think 440BX can tell you device type? FIXME? */
218 csrow->dtype = DEV_UNKNOWN;
219 /* Mode is global to all rows on 440BX */
220 csrow->edac_mode = edac_mode;
221 row_high_limit_last = row_high_limit;
222 }
223}
224
Douglas Thompson11116602007-07-19 01:50:07 -0700225static int i82443bxgx_edacmc_probe1(struct pci_dev *pdev, int dev_idx)
Tim Small5a2c6752007-07-19 01:49:42 -0700226{
227 struct mem_ctl_info *mci;
228 u8 dramc;
229 u32 nbxcfg, ecc_mode;
230 enum mem_type mtype;
231 enum edac_type edac_mode;
232
233 debugf0("MC: " __FILE__ ": %s()\n", __func__);
234
235 /* Something is really hosed if PCI config space reads from
236 the MC aren't working. */
237 if (pci_read_config_dword(pdev, I82443BXGX_NBXCFG, &nbxcfg))
238 return -EIO;
239
240 mci = edac_mc_alloc(0, I82443BXGX_NR_CSROWS, I82443BXGX_NR_CHANS);
241
242 if (mci == NULL)
243 return -ENOMEM;
244
245 debugf0("MC: " __FILE__ ": %s(): mci = %p\n", __func__, mci);
246 mci->dev = &pdev->dev;
247 mci->mtype_cap = MEM_FLAG_EDO | MEM_FLAG_SDR | MEM_FLAG_RDR;
248 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED;
249 pci_read_config_byte(pdev, I82443BXGX_DRAMC, &dramc);
250 switch ((dramc >> I82443BXGX_DRAMC_OFFSET_DT) & (BIT(0) | BIT(1))) {
Douglas Thompson11116602007-07-19 01:50:07 -0700251 case I82443BXGX_DRAMC_DRAM_IS_EDO:
Tim Small5a2c6752007-07-19 01:49:42 -0700252 mtype = MEM_EDO;
253 break;
254 case I82443BXGX_DRAMC_DRAM_IS_SDRAM:
255 mtype = MEM_SDR;
256 break;
257 case I82443BXGX_DRAMC_DRAM_IS_RSDRAM:
258 mtype = MEM_RDR;
259 break;
260 default:
Douglas Thompson11116602007-07-19 01:50:07 -0700261 debugf0
262 ("Unknown/reserved DRAM type value in DRAMC register!\n");
Tim Small5a2c6752007-07-19 01:49:42 -0700263 mtype = -MEM_UNKNOWN;
264 }
265
266 if ((mtype == MEM_SDR) || (mtype == MEM_RDR))
267 mci->edac_cap = mci->edac_ctl_cap;
268 else
269 mci->edac_cap = EDAC_FLAG_NONE;
270
271 mci->scrub_cap = SCRUB_FLAG_HW_SRC;
272 pci_read_config_dword(pdev, I82443BXGX_NBXCFG, &nbxcfg);
273 ecc_mode = ((nbxcfg >> I82443BXGX_NBXCFG_OFFSET_DRAM_INTEGRITY) &
Douglas Thompson11116602007-07-19 01:50:07 -0700274 (BIT(0) | BIT(1)));
Tim Small5a2c6752007-07-19 01:49:42 -0700275
276 mci->scrub_mode = (ecc_mode == I82443BXGX_NBXCFG_INTEGRITY_SCRUB)
Douglas Thompson11116602007-07-19 01:50:07 -0700277 ? SCRUB_HW_SRC : SCRUB_NONE;
Tim Small5a2c6752007-07-19 01:49:42 -0700278
Douglas Thompson11116602007-07-19 01:50:07 -0700279 switch (ecc_mode) {
Tim Small5a2c6752007-07-19 01:49:42 -0700280 case I82443BXGX_NBXCFG_INTEGRITY_NONE:
281 edac_mode = EDAC_NONE;
282 break;
283 case I82443BXGX_NBXCFG_INTEGRITY_EC:
284 edac_mode = EDAC_EC;
285 break;
286 case I82443BXGX_NBXCFG_INTEGRITY_ECC:
287 case I82443BXGX_NBXCFG_INTEGRITY_SCRUB:
288 edac_mode = EDAC_SECDED;
289 break;
290 default:
Douglas Thompson11116602007-07-19 01:50:07 -0700291 debugf0
292 ("%s(): Unknown/reserved ECC state in NBXCFG register!\n",
293 __func__);
Tim Small5a2c6752007-07-19 01:49:42 -0700294 edac_mode = EDAC_UNKNOWN;
295 break;
296 }
297
298 i82443bxgx_init_csrows(mci, pdev, edac_mode, mtype);
299
300 /* Many BIOSes don't clear error flags on boot, so do this
301 * here, or we get "phantom" errors occuring at module-load
302 * time. */
303 pci_write_bits32(pdev, I82443BXGX_EAP,
Douglas Thompson11116602007-07-19 01:50:07 -0700304 (I82443BXGX_EAP_OFFSET_SBE |
305 I82443BXGX_EAP_OFFSET_MBE),
306 (I82443BXGX_EAP_OFFSET_SBE |
307 I82443BXGX_EAP_OFFSET_MBE));
Tim Small5a2c6752007-07-19 01:49:42 -0700308
309 mci->mod_name = EDAC_MOD_STR;
310 mci->mod_ver = I82443_REVISION;
311 mci->ctl_name = "I82443BXGX";
Dave Jiangc4192702007-07-19 01:49:47 -0700312 mci->dev_name = pci_name(pdev);
Tim Small5a2c6752007-07-19 01:49:42 -0700313 mci->edac_check = i82443bxgx_edacmc_check;
314 mci->ctl_page_to_phys = NULL;
315
316 if (edac_mc_add_mc(mci, 0)) {
317 debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
318 goto fail;
319 }
320
Dave Jiang456a2f92007-07-19 01:50:10 -0700321 /* allocating generic PCI control info */
322 i82443bxgx_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
323 if (!i82443bxgx_pci) {
324 printk(KERN_WARNING
325 "%s(): Unable to create PCI control\n",
326 __func__);
327 printk(KERN_WARNING
328 "%s(): PCI error report via EDAC not setup\n",
329 __func__);
330 }
331
Tim Small5a2c6752007-07-19 01:49:42 -0700332 debugf3("MC: " __FILE__ ": %s(): success\n", __func__);
333 return 0;
334
Douglas Thompson11116602007-07-19 01:50:07 -0700335 fail:
Tim Small5a2c6752007-07-19 01:49:42 -0700336 edac_mc_free(mci);
337 return -ENODEV;
338}
Douglas Thompson11116602007-07-19 01:50:07 -0700339
Tim Small5a2c6752007-07-19 01:49:42 -0700340EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_probe1);
341
342/* returns count (>= 0), or negative on error */
343static int __devinit i82443bxgx_edacmc_init_one(struct pci_dev *pdev,
Douglas Thompson11116602007-07-19 01:50:07 -0700344 const struct pci_device_id *ent)
Tim Small5a2c6752007-07-19 01:49:42 -0700345{
346 debugf0("MC: " __FILE__ ": %s()\n", __func__);
347
348 /* don't need to call pci_device_enable() */
Douglas Thompson11116602007-07-19 01:50:07 -0700349 return i82443bxgx_edacmc_probe1(pdev, ent->driver_data);
Tim Small5a2c6752007-07-19 01:49:42 -0700350}
351
Tim Small5a2c6752007-07-19 01:49:42 -0700352static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
353{
354 struct mem_ctl_info *mci;
355
356 debugf0(__FILE__ ": %s()\n", __func__);
357
Dave Jiang456a2f92007-07-19 01:50:10 -0700358 if (i82443bxgx_pci)
359 edac_pci_release_generic_ctl(i82443bxgx_pci);
360
Douglas Thompson11116602007-07-19 01:50:07 -0700361 if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
Tim Small5a2c6752007-07-19 01:49:42 -0700362 return;
363
364 edac_mc_free(mci);
365}
Tim Small5a2c6752007-07-19 01:49:42 -0700366
Douglas Thompson11116602007-07-19 01:50:07 -0700367EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
Tim Small5a2c6752007-07-19 01:49:42 -0700368
369static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
370 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
371 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
372 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
373 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_2)},
374 {0,} /* 0 terminated list. */
375};
376
377MODULE_DEVICE_TABLE(pci, i82443bxgx_pci_tbl);
378
Tim Small5a2c6752007-07-19 01:49:42 -0700379static struct pci_driver i82443bxgx_edacmc_driver = {
380 .name = EDAC_MOD_STR,
381 .probe = i82443bxgx_edacmc_init_one,
382 .remove = __devexit_p(i82443bxgx_edacmc_remove_one),
383 .id_table = i82443bxgx_pci_tbl,
384};
385
Tim Small5a2c6752007-07-19 01:49:42 -0700386static int __init i82443bxgx_edacmc_init(void)
387{
388 return pci_register_driver(&i82443bxgx_edacmc_driver);
389}
390
Tim Small5a2c6752007-07-19 01:49:42 -0700391static void __exit i82443bxgx_edacmc_exit(void)
392{
393 pci_unregister_driver(&i82443bxgx_edacmc_driver);
394}
395
Tim Small5a2c6752007-07-19 01:49:42 -0700396module_init(i82443bxgx_edacmc_init);
397module_exit(i82443bxgx_edacmc_exit);
398
Tim Small5a2c6752007-07-19 01:49:42 -0700399MODULE_LICENSE("GPL");
400MODULE_AUTHOR("Tim Small <tim@buttersideup.com> - WPAD");
401MODULE_DESCRIPTION("EDAC MC support for Intel 82443BX/GX memory controllers");