i82875p_edac.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. /*
  2. * Intel D82875P Memory Controller kernel module
  3. * (C) 2003 Linux Networx (http://lnxi.com)
  4. * This file may be distributed under the terms of the
  5. * GNU General Public License.
  6. *
  7. * Written by Thayne Harbaugh
  8. * Contributors:
  9. * Wang Zhenyu at intel.com
  10. *
  11. * $Id: edac_i82875p.c,v 1.5.2.11 2005/10/05 00:43:44 dsp_llnl Exp $
  12. *
  13. * Note: E7210 appears same as D82875P - zhenyu.z.wang at intel.com
  14. */
  15. #include <linux/module.h>
  16. #include <linux/init.h>
  17. #include <linux/pci.h>
  18. #include <linux/pci_ids.h>
  19. #include <linux/slab.h>
  20. #include "edac_mc.h"
  21. #define I82875P_REVISION " Ver: 2.0.1 " __DATE__
  22. #define EDAC_MOD_STR "i82875p_edac"
  23. #define i82875p_printk(level, fmt, arg...) \
  24. edac_printk(level, "i82875p", fmt, ##arg)
  25. #define i82875p_mc_printk(mci, level, fmt, arg...) \
  26. edac_mc_chipset_printk(mci, level, "i82875p", fmt, ##arg)
  27. #ifndef PCI_DEVICE_ID_INTEL_82875_0
  28. #define PCI_DEVICE_ID_INTEL_82875_0 0x2578
  29. #endif /* PCI_DEVICE_ID_INTEL_82875_0 */
  30. #ifndef PCI_DEVICE_ID_INTEL_82875_6
  31. #define PCI_DEVICE_ID_INTEL_82875_6 0x257e
  32. #endif /* PCI_DEVICE_ID_INTEL_82875_6 */
  33. /* four csrows in dual channel, eight in single channel */
  34. #define I82875P_NR_CSROWS(nr_chans) (8/(nr_chans))
  35. /* Intel 82875p register addresses - device 0 function 0 - DRAM Controller */
  36. #define I82875P_EAP 0x58 /* Error Address Pointer (32b)
  37. *
  38. * 31:12 block address
  39. * 11:0 reserved
  40. */
  41. #define I82875P_DERRSYN 0x5c /* DRAM Error Syndrome (8b)
  42. *
  43. * 7:0 DRAM ECC Syndrome
  44. */
  45. #define I82875P_DES 0x5d /* DRAM Error Status (8b)
  46. *
  47. * 7:1 reserved
  48. * 0 Error channel 0/1
  49. */
  50. #define I82875P_ERRSTS 0xc8 /* Error Status Register (16b)
  51. *
  52. * 15:10 reserved
  53. * 9 non-DRAM lock error (ndlock)
  54. * 8 Sftwr Generated SMI
  55. * 7 ECC UE
  56. * 6 reserved
  57. * 5 MCH detects unimplemented cycle
  58. * 4 AGP access outside GA
  59. * 3 Invalid AGP access
  60. * 2 Invalid GA translation table
  61. * 1 Unsupported AGP command
  62. * 0 ECC CE
  63. */
  64. #define I82875P_ERRCMD 0xca /* Error Command (16b)
  65. *
  66. * 15:10 reserved
  67. * 9 SERR on non-DRAM lock
  68. * 8 SERR on ECC UE
  69. * 7 SERR on ECC CE
  70. * 6 target abort on high exception
  71. * 5 detect unimplemented cyc
  72. * 4 AGP access outside of GA
  73. * 3 SERR on invalid AGP access
  74. * 2 invalid translation table
  75. * 1 SERR on unsupported AGP command
  76. * 0 reserved
  77. */
  78. /* Intel 82875p register addresses - device 6 function 0 - DRAM Controller */
  79. #define I82875P_PCICMD6 0x04 /* PCI Command Register (16b)
  80. *
  81. * 15:10 reserved
  82. * 9 fast back-to-back - ro 0
  83. * 8 SERR enable - ro 0
  84. * 7 addr/data stepping - ro 0
  85. * 6 parity err enable - ro 0
  86. * 5 VGA palette snoop - ro 0
  87. * 4 mem wr & invalidate - ro 0
  88. * 3 special cycle - ro 0
  89. * 2 bus master - ro 0
  90. * 1 mem access dev6 - 0(dis),1(en)
  91. * 0 IO access dev3 - 0(dis),1(en)
  92. */
  93. #define I82875P_BAR6 0x10 /* Mem Delays Base ADDR Reg (32b)
  94. *
  95. * 31:12 mem base addr [31:12]
  96. * 11:4 address mask - ro 0
  97. * 3 prefetchable - ro 0(non),1(pre)
  98. * 2:1 mem type - ro 0
  99. * 0 mem space - ro 0
  100. */
  101. /* Intel 82875p MMIO register space - device 0 function 0 - MMR space */
  102. #define I82875P_DRB_SHIFT 26 /* 64MiB grain */
  103. #define I82875P_DRB 0x00 /* DRAM Row Boundary (8b x 8)
  104. *
  105. * 7 reserved
  106. * 6:0 64MiB row boundary addr
  107. */
  108. #define I82875P_DRA 0x10 /* DRAM Row Attribute (4b x 8)
  109. *
  110. * 7 reserved
  111. * 6:4 row attr row 1
  112. * 3 reserved
  113. * 2:0 row attr row 0
  114. *
  115. * 000 = 4KiB
  116. * 001 = 8KiB
  117. * 010 = 16KiB
  118. * 011 = 32KiB
  119. */
  120. #define I82875P_DRC 0x68 /* DRAM Controller Mode (32b)
  121. *
  122. * 31:30 reserved
  123. * 29 init complete
  124. * 28:23 reserved
  125. * 22:21 nr chan 00=1,01=2
  126. * 20 reserved
  127. * 19:18 Data Integ Mode 00=none,01=ecc
  128. * 17:11 reserved
  129. * 10:8 refresh mode
  130. * 7 reserved
  131. * 6:4 mode select
  132. * 3:2 reserved
  133. * 1:0 DRAM type 01=DDR
  134. */
  135. enum i82875p_chips {
  136. I82875P = 0,
  137. };
  138. struct i82875p_pvt {
  139. struct pci_dev *ovrfl_pdev;
  140. void __iomem *ovrfl_window;
  141. };
  142. struct i82875p_dev_info {
  143. const char *ctl_name;
  144. };
  145. struct i82875p_error_info {
  146. u16 errsts;
  147. u32 eap;
  148. u8 des;
  149. u8 derrsyn;
  150. u16 errsts2;
  151. };
  152. static const struct i82875p_dev_info i82875p_devs[] = {
  153. [I82875P] = {
  154. .ctl_name = "i82875p"
  155. },
  156. };
  157. static struct pci_dev *mci_pdev = NULL; /* init dev: in case that AGP code has
  158. * already registered driver
  159. */
  160. static int i82875p_registered = 1;
  161. static void i82875p_get_error_info(struct mem_ctl_info *mci,
  162. struct i82875p_error_info *info)
  163. {
  164. struct pci_dev *pdev;
  165. pdev = to_pci_dev(mci->dev);
  166. /*
  167. * This is a mess because there is no atomic way to read all the
  168. * registers at once and the registers can transition from CE being
  169. * overwritten by UE.
  170. */
  171. pci_read_config_word(pdev, I82875P_ERRSTS, &info->errsts);
  172. pci_read_config_dword(pdev, I82875P_EAP, &info->eap);
  173. pci_read_config_byte(pdev, I82875P_DES, &info->des);
  174. pci_read_config_byte(pdev, I82875P_DERRSYN, &info->derrsyn);
  175. pci_read_config_word(pdev, I82875P_ERRSTS, &info->errsts2);
  176. pci_write_bits16(pdev, I82875P_ERRSTS, 0x0081, 0x0081);
  177. /*
  178. * If the error is the same then we can for both reads then
  179. * the first set of reads is valid. If there is a change then
  180. * there is a CE no info and the second set of reads is valid
  181. * and should be UE info.
  182. */
  183. if (!(info->errsts2 & 0x0081))
  184. return;
  185. if ((info->errsts ^ info->errsts2) & 0x0081) {
  186. pci_read_config_dword(pdev, I82875P_EAP, &info->eap);
  187. pci_read_config_byte(pdev, I82875P_DES, &info->des);
  188. pci_read_config_byte(pdev, I82875P_DERRSYN,
  189. &info->derrsyn);
  190. }
  191. }
  192. static int i82875p_process_error_info(struct mem_ctl_info *mci,
  193. struct i82875p_error_info *info, int handle_errors)
  194. {
  195. int row, multi_chan;
  196. multi_chan = mci->csrows[0].nr_channels - 1;
  197. if (!(info->errsts2 & 0x0081))
  198. return 0;
  199. if (!handle_errors)
  200. return 1;
  201. if ((info->errsts ^ info->errsts2) & 0x0081) {
  202. edac_mc_handle_ce_no_info(mci, "UE overwrote CE");
  203. info->errsts = info->errsts2;
  204. }
  205. info->eap >>= PAGE_SHIFT;
  206. row = edac_mc_find_csrow_by_page(mci, info->eap);
  207. if (info->errsts & 0x0080)
  208. edac_mc_handle_ue(mci, info->eap, 0, row, "i82875p UE");
  209. else
  210. edac_mc_handle_ce(mci, info->eap, 0, info->derrsyn, row,
  211. multi_chan ? (info->des & 0x1) : 0,
  212. "i82875p CE");
  213. return 1;
  214. }
  215. static void i82875p_check(struct mem_ctl_info *mci)
  216. {
  217. struct i82875p_error_info info;
  218. debugf1("MC%d: %s()\n", mci->mc_idx, __func__);
  219. i82875p_get_error_info(mci, &info);
  220. i82875p_process_error_info(mci, &info, 1);
  221. }
  222. #ifdef CONFIG_PROC_FS
  223. extern int pci_proc_attach_device(struct pci_dev *);
  224. #endif
  225. /* Return 0 on success or 1 on failure. */
  226. static int i82875p_setup_overfl_dev(struct pci_dev *pdev,
  227. struct pci_dev **ovrfl_pdev, void __iomem **ovrfl_window)
  228. {
  229. struct pci_dev *dev;
  230. void __iomem *window;
  231. *ovrfl_pdev = NULL;
  232. *ovrfl_window = NULL;
  233. dev = pci_get_device(PCI_VEND_DEV(INTEL, 82875_6), NULL);
  234. if (dev == NULL) {
  235. /* Intel tells BIOS developers to hide device 6 which
  236. * configures the overflow device access containing
  237. * the DRBs - this is where we expose device 6.
  238. * http://www.x86-secret.com/articles/tweak/pat/patsecrets-2.htm
  239. */
  240. pci_write_bits8(pdev, 0xf4, 0x2, 0x2);
  241. dev = pci_scan_single_device(pdev->bus, PCI_DEVFN(6, 0));
  242. if (dev == NULL)
  243. return 1;
  244. }
  245. *ovrfl_pdev = dev;
  246. #ifdef CONFIG_PROC_FS
  247. if ((dev->procent == NULL) && pci_proc_attach_device(dev)) {
  248. i82875p_printk(KERN_ERR, "%s(): Failed to attach overflow "
  249. "device\n", __func__);
  250. return 1;
  251. }
  252. #endif /* CONFIG_PROC_FS */
  253. if (pci_enable_device(dev)) {
  254. i82875p_printk(KERN_ERR, "%s(): Failed to enable overflow "
  255. "device\n", __func__);
  256. return 1;
  257. }
  258. if (pci_request_regions(dev, pci_name(dev))) {
  259. #ifdef CORRECT_BIOS
  260. goto fail0;
  261. #endif
  262. }
  263. /* cache is irrelevant for PCI bus reads/writes */
  264. window = ioremap_nocache(pci_resource_start(dev, 0),
  265. pci_resource_len(dev, 0));
  266. if (window == NULL) {
  267. i82875p_printk(KERN_ERR, "%s(): Failed to ioremap bar6\n",
  268. __func__);
  269. goto fail1;
  270. }
  271. *ovrfl_window = window;
  272. return 0;
  273. fail1:
  274. pci_release_regions(dev);
  275. #ifdef CORRECT_BIOS
  276. fail0:
  277. pci_disable_device(dev);
  278. #endif
  279. /* NOTE: the ovrfl proc entry and pci_dev are intentionally left */
  280. return 1;
  281. }
  282. /* Return 1 if dual channel mode is active. Else return 0. */
  283. static inline int dual_channel_active(u32 drc)
  284. {
  285. return (drc >> 21) & 0x1;
  286. }
  287. static void i82875p_init_csrows(struct mem_ctl_info *mci,
  288. struct pci_dev *pdev, void __iomem *ovrfl_window, u32 drc)
  289. {
  290. struct csrow_info *csrow;
  291. unsigned long last_cumul_size;
  292. u8 value;
  293. u32 drc_ddim; /* DRAM Data Integrity Mode 0=none,2=edac */
  294. u32 cumul_size;
  295. int index;
  296. drc_ddim = (drc >> 18) & 0x1;
  297. last_cumul_size = 0;
  298. /* The dram row boundary (DRB) reg values are boundary address
  299. * for each DRAM row with a granularity of 32 or 64MB (single/dual
  300. * channel operation). DRB regs are cumulative; therefore DRB7 will
  301. * contain the total memory contained in all eight rows.
  302. */
  303. for (index = 0; index < mci->nr_csrows; index++) {
  304. csrow = &mci->csrows[index];
  305. value = readb(ovrfl_window + I82875P_DRB + index);
  306. cumul_size = value << (I82875P_DRB_SHIFT - PAGE_SHIFT);
  307. debugf3("%s(): (%d) cumul_size 0x%x\n", __func__, index,
  308. cumul_size);
  309. if (cumul_size == last_cumul_size)
  310. continue; /* not populated */
  311. csrow->first_page = last_cumul_size;
  312. csrow->last_page = cumul_size - 1;
  313. csrow->nr_pages = cumul_size - last_cumul_size;
  314. last_cumul_size = cumul_size;
  315. csrow->grain = 1 << 12; /* I82875P_EAP has 4KiB reolution */
  316. csrow->mtype = MEM_DDR;
  317. csrow->dtype = DEV_UNKNOWN;
  318. csrow->edac_mode = drc_ddim ? EDAC_SECDED : EDAC_NONE;
  319. }
  320. }
  321. static int i82875p_probe1(struct pci_dev *pdev, int dev_idx)
  322. {
  323. int rc = -ENODEV;
  324. struct mem_ctl_info *mci;
  325. struct i82875p_pvt *pvt;
  326. struct pci_dev *ovrfl_pdev;
  327. void __iomem *ovrfl_window;
  328. u32 drc;
  329. u32 nr_chans;
  330. struct i82875p_error_info discard;
  331. debugf0("%s()\n", __func__);
  332. ovrfl_pdev = pci_get_device(PCI_VEND_DEV(INTEL, 82875_6), NULL);
  333. if (i82875p_setup_overfl_dev(pdev, &ovrfl_pdev, &ovrfl_window))
  334. return -ENODEV;
  335. drc = readl(ovrfl_window + I82875P_DRC);
  336. nr_chans = dual_channel_active(drc) + 1;
  337. mci = edac_mc_alloc(sizeof(*pvt), I82875P_NR_CSROWS(nr_chans),
  338. nr_chans);
  339. if (!mci) {
  340. rc = -ENOMEM;
  341. goto fail0;
  342. }
  343. debugf3("%s(): init mci\n", __func__);
  344. mci->dev = &pdev->dev;
  345. mci->mtype_cap = MEM_FLAG_DDR;
  346. mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
  347. mci->edac_cap = EDAC_FLAG_UNKNOWN;
  348. mci->mod_name = EDAC_MOD_STR;
  349. mci->mod_ver = I82875P_REVISION;
  350. mci->ctl_name = i82875p_devs[dev_idx].ctl_name;
  351. mci->edac_check = i82875p_check;
  352. mci->ctl_page_to_phys = NULL;
  353. debugf3("%s(): init pvt\n", __func__);
  354. pvt = (struct i82875p_pvt *) mci->pvt_info;
  355. pvt->ovrfl_pdev = ovrfl_pdev;
  356. pvt->ovrfl_window = ovrfl_window;
  357. i82875p_init_csrows(mci, pdev, ovrfl_window, drc);
  358. i82875p_get_error_info(mci, &discard); /* clear counters */
  359. /* Here we assume that we will never see multiple instances of this
  360. * type of memory controller. The ID is therefore hardcoded to 0.
  361. */
  362. if (edac_mc_add_mc(mci,0)) {
  363. debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
  364. goto fail1;
  365. }
  366. /* get this far and it's successful */
  367. debugf3("%s(): success\n", __func__);
  368. return 0;
  369. fail1:
  370. edac_mc_free(mci);
  371. fail0:
  372. iounmap(ovrfl_window);
  373. pci_release_regions(ovrfl_pdev);
  374. pci_disable_device(ovrfl_pdev);
  375. /* NOTE: the ovrfl proc entry and pci_dev are intentionally left */
  376. return rc;
  377. }
  378. /* returns count (>= 0), or negative on error */
  379. static int __devinit i82875p_init_one(struct pci_dev *pdev,
  380. const struct pci_device_id *ent)
  381. {
  382. int rc;
  383. debugf0("%s()\n", __func__);
  384. i82875p_printk(KERN_INFO, "i82875p init one\n");
  385. if (pci_enable_device(pdev) < 0)
  386. return -EIO;
  387. rc = i82875p_probe1(pdev, ent->driver_data);
  388. if (mci_pdev == NULL)
  389. mci_pdev = pci_dev_get(pdev);
  390. return rc;
  391. }
  392. static void __devexit i82875p_remove_one(struct pci_dev *pdev)
  393. {
  394. struct mem_ctl_info *mci;
  395. struct i82875p_pvt *pvt = NULL;
  396. debugf0("%s()\n", __func__);
  397. if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
  398. return;
  399. pvt = (struct i82875p_pvt *) mci->pvt_info;
  400. if (pvt->ovrfl_window)
  401. iounmap(pvt->ovrfl_window);
  402. if (pvt->ovrfl_pdev) {
  403. #ifdef CORRECT_BIOS
  404. pci_release_regions(pvt->ovrfl_pdev);
  405. #endif /*CORRECT_BIOS */
  406. pci_disable_device(pvt->ovrfl_pdev);
  407. pci_dev_put(pvt->ovrfl_pdev);
  408. }
  409. edac_mc_free(mci);
  410. }
  411. static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
  412. {
  413. PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  414. I82875P
  415. },
  416. {
  417. 0,
  418. } /* 0 terminated list. */
  419. };
  420. MODULE_DEVICE_TABLE(pci, i82875p_pci_tbl);
  421. static struct pci_driver i82875p_driver = {
  422. .name = EDAC_MOD_STR,
  423. .probe = i82875p_init_one,
  424. .remove = __devexit_p(i82875p_remove_one),
  425. .id_table = i82875p_pci_tbl,
  426. };
  427. static int __init i82875p_init(void)
  428. {
  429. int pci_rc;
  430. debugf3("%s()\n", __func__);
  431. pci_rc = pci_register_driver(&i82875p_driver);
  432. if (pci_rc < 0)
  433. goto fail0;
  434. if (mci_pdev == NULL) {
  435. mci_pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  436. PCI_DEVICE_ID_INTEL_82875_0, NULL);
  437. if (!mci_pdev) {
  438. debugf0("875p pci_get_device fail\n");
  439. pci_rc = -ENODEV;
  440. goto fail1;
  441. }
  442. pci_rc = i82875p_init_one(mci_pdev, i82875p_pci_tbl);
  443. if (pci_rc < 0) {
  444. debugf0("875p init fail\n");
  445. pci_rc = -ENODEV;
  446. goto fail1;
  447. }
  448. }
  449. return 0;
  450. fail1:
  451. pci_unregister_driver(&i82875p_driver);
  452. fail0:
  453. if (mci_pdev != NULL)
  454. pci_dev_put(mci_pdev);
  455. return pci_rc;
  456. }
  457. static void __exit i82875p_exit(void)
  458. {
  459. debugf3("%s()\n", __func__);
  460. pci_unregister_driver(&i82875p_driver);
  461. if (!i82875p_registered) {
  462. i82875p_remove_one(mci_pdev);
  463. pci_dev_put(mci_pdev);
  464. }
  465. }
  466. module_init(i82875p_init);
  467. module_exit(i82875p_exit);
  468. MODULE_LICENSE("GPL");
  469. MODULE_AUTHOR("Linux Networx (http://lnxi.com) Thayne Harbaugh");
  470. MODULE_DESCRIPTION("MC support for Intel 82875 memory hub controllers");