i82875p_edac.c 15 KB

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