i82875p_edac.c 13 KB

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