i82860_edac.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /*
  2. * Intel 82860 Memory Controller kernel module
  3. * (C) 2005 Red Hat (http://www.redhat.com)
  4. * This file may be distributed under the terms of the
  5. * GNU General Public License.
  6. *
  7. * Written by Ben Woodard <woodard@redhat.com>
  8. * shamelessly copied from and based upon the edac_i82875 driver
  9. * by Thayne Harbaugh of Linux Networx. (http://lnxi.com)
  10. */
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/pci.h>
  14. #include <linux/pci_ids.h>
  15. #include <linux/edac.h>
  16. #include "edac_core.h"
  17. #define I82860_REVISION " Ver: 2.0.2"
  18. #define EDAC_MOD_STR "i82860_edac"
  19. #define i82860_printk(level, fmt, arg...) \
  20. edac_printk(level, "i82860", fmt, ##arg)
  21. #define i82860_mc_printk(mci, level, fmt, arg...) \
  22. edac_mc_chipset_printk(mci, level, "i82860", fmt, ##arg)
  23. #ifndef PCI_DEVICE_ID_INTEL_82860_0
  24. #define PCI_DEVICE_ID_INTEL_82860_0 0x2531
  25. #endif /* PCI_DEVICE_ID_INTEL_82860_0 */
  26. #define I82860_MCHCFG 0x50
  27. #define I82860_GBA 0x60
  28. #define I82860_GBA_MASK 0x7FF
  29. #define I82860_GBA_SHIFT 24
  30. #define I82860_ERRSTS 0xC8
  31. #define I82860_EAP 0xE4
  32. #define I82860_DERRCTL_STS 0xE2
  33. enum i82860_chips {
  34. I82860 = 0,
  35. };
  36. struct i82860_dev_info {
  37. const char *ctl_name;
  38. };
  39. struct i82860_error_info {
  40. u16 errsts;
  41. u32 eap;
  42. u16 derrsyn;
  43. u16 errsts2;
  44. };
  45. static const struct i82860_dev_info i82860_devs[] = {
  46. [I82860] = {
  47. .ctl_name = "i82860"},
  48. };
  49. static struct pci_dev *mci_pdev; /* init dev: in case that AGP code
  50. * has already registered driver
  51. */
  52. static struct edac_pci_ctl_info *i82860_pci;
  53. static void i82860_get_error_info(struct mem_ctl_info *mci,
  54. struct i82860_error_info *info)
  55. {
  56. struct pci_dev *pdev;
  57. pdev = to_pci_dev(mci->dev);
  58. /*
  59. * This is a mess because there is no atomic way to read all the
  60. * registers at once and the registers can transition from CE being
  61. * overwritten by UE.
  62. */
  63. pci_read_config_word(pdev, I82860_ERRSTS, &info->errsts);
  64. pci_read_config_dword(pdev, I82860_EAP, &info->eap);
  65. pci_read_config_word(pdev, I82860_DERRCTL_STS, &info->derrsyn);
  66. pci_read_config_word(pdev, I82860_ERRSTS, &info->errsts2);
  67. pci_write_bits16(pdev, I82860_ERRSTS, 0x0003, 0x0003);
  68. /*
  69. * If the error is the same for both reads then the first set of reads
  70. * is valid. If there is a change then there is a CE no info and the
  71. * second set of reads is valid and should be UE info.
  72. */
  73. if (!(info->errsts2 & 0x0003))
  74. return;
  75. if ((info->errsts ^ info->errsts2) & 0x0003) {
  76. pci_read_config_dword(pdev, I82860_EAP, &info->eap);
  77. pci_read_config_word(pdev, I82860_DERRCTL_STS, &info->derrsyn);
  78. }
  79. }
  80. static int i82860_process_error_info(struct mem_ctl_info *mci,
  81. struct i82860_error_info *info,
  82. int handle_errors)
  83. {
  84. int row;
  85. if (!(info->errsts2 & 0x0003))
  86. return 0;
  87. if (!handle_errors)
  88. return 1;
  89. if ((info->errsts ^ info->errsts2) & 0x0003) {
  90. edac_mc_handle_ce_no_info(mci, "UE overwrote CE");
  91. info->errsts = info->errsts2;
  92. }
  93. info->eap >>= PAGE_SHIFT;
  94. row = edac_mc_find_csrow_by_page(mci, info->eap);
  95. if (info->errsts & 0x0002)
  96. edac_mc_handle_ue(mci, info->eap, 0, row, "i82860 UE");
  97. else
  98. edac_mc_handle_ce(mci, info->eap, 0, info->derrsyn, row, 0,
  99. "i82860 UE");
  100. return 1;
  101. }
  102. static void i82860_check(struct mem_ctl_info *mci)
  103. {
  104. struct i82860_error_info info;
  105. debugf1("MC%d: %s()\n", mci->mc_idx, __func__);
  106. i82860_get_error_info(mci, &info);
  107. i82860_process_error_info(mci, &info, 1);
  108. }
  109. static void i82860_init_csrows(struct mem_ctl_info *mci, struct pci_dev *pdev)
  110. {
  111. unsigned long last_cumul_size;
  112. u16 mchcfg_ddim; /* DRAM Data Integrity Mode 0=none, 2=edac */
  113. u16 value;
  114. u32 cumul_size;
  115. struct csrow_info *csrow;
  116. int index;
  117. pci_read_config_word(pdev, I82860_MCHCFG, &mchcfg_ddim);
  118. mchcfg_ddim = mchcfg_ddim & 0x180;
  119. last_cumul_size = 0;
  120. /* The group row boundary (GRA) reg values are boundary address
  121. * for each DRAM row with a granularity of 16MB. GRA regs are
  122. * cumulative; therefore GRA15 will contain the total memory contained
  123. * in all eight rows.
  124. */
  125. for (index = 0; index < mci->nr_csrows; index++) {
  126. csrow = &mci->csrows[index];
  127. pci_read_config_word(pdev, I82860_GBA + index * 2, &value);
  128. cumul_size = (value & I82860_GBA_MASK) <<
  129. (I82860_GBA_SHIFT - PAGE_SHIFT);
  130. debugf3("%s(): (%d) cumul_size 0x%x\n", __func__, index,
  131. cumul_size);
  132. if (cumul_size == last_cumul_size)
  133. continue; /* not populated */
  134. csrow->first_page = last_cumul_size;
  135. csrow->last_page = cumul_size - 1;
  136. csrow->nr_pages = cumul_size - last_cumul_size;
  137. last_cumul_size = cumul_size;
  138. csrow->grain = 1 << 12; /* I82860_EAP has 4KiB reolution */
  139. csrow->mtype = MEM_RMBS;
  140. csrow->dtype = DEV_UNKNOWN;
  141. csrow->edac_mode = mchcfg_ddim ? EDAC_SECDED : EDAC_NONE;
  142. }
  143. }
  144. static int i82860_probe1(struct pci_dev *pdev, int dev_idx)
  145. {
  146. struct mem_ctl_info *mci;
  147. struct i82860_error_info discard;
  148. /* RDRAM has channels but these don't map onto the abstractions that
  149. edac uses.
  150. The device groups from the GRA registers seem to map reasonably
  151. well onto the notion of a chip select row.
  152. There are 16 GRA registers and since the name is associated with
  153. the channel and the GRA registers map to physical devices so we are
  154. going to make 1 channel for group.
  155. */
  156. mci = edac_mc_alloc(0, 16, 1, 0);
  157. if (!mci)
  158. return -ENOMEM;
  159. debugf3("%s(): init mci\n", __func__);
  160. mci->dev = &pdev->dev;
  161. mci->mtype_cap = MEM_FLAG_DDR;
  162. mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
  163. /* I"m not sure about this but I think that all RDRAM is SECDED */
  164. mci->edac_cap = EDAC_FLAG_SECDED;
  165. mci->mod_name = EDAC_MOD_STR;
  166. mci->mod_ver = I82860_REVISION;
  167. mci->ctl_name = i82860_devs[dev_idx].ctl_name;
  168. mci->dev_name = pci_name(pdev);
  169. mci->edac_check = i82860_check;
  170. mci->ctl_page_to_phys = NULL;
  171. i82860_init_csrows(mci, pdev);
  172. i82860_get_error_info(mci, &discard); /* clear counters */
  173. /* Here we assume that we will never see multiple instances of this
  174. * type of memory controller. The ID is therefore hardcoded to 0.
  175. */
  176. if (edac_mc_add_mc(mci)) {
  177. debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
  178. goto fail;
  179. }
  180. /* allocating generic PCI control info */
  181. i82860_pci = edac_pci_create_generic_ctl(&pdev->dev, EDAC_MOD_STR);
  182. if (!i82860_pci) {
  183. printk(KERN_WARNING
  184. "%s(): Unable to create PCI control\n",
  185. __func__);
  186. printk(KERN_WARNING
  187. "%s(): PCI error report via EDAC not setup\n",
  188. __func__);
  189. }
  190. /* get this far and it's successful */
  191. debugf3("%s(): success\n", __func__);
  192. return 0;
  193. fail:
  194. edac_mc_free(mci);
  195. return -ENODEV;
  196. }
  197. /* returns count (>= 0), or negative on error */
  198. static int __devinit i82860_init_one(struct pci_dev *pdev,
  199. const struct pci_device_id *ent)
  200. {
  201. int rc;
  202. debugf0("%s()\n", __func__);
  203. i82860_printk(KERN_INFO, "i82860 init one\n");
  204. if (pci_enable_device(pdev) < 0)
  205. return -EIO;
  206. rc = i82860_probe1(pdev, ent->driver_data);
  207. if (rc == 0)
  208. mci_pdev = pci_dev_get(pdev);
  209. return rc;
  210. }
  211. static void __devexit i82860_remove_one(struct pci_dev *pdev)
  212. {
  213. struct mem_ctl_info *mci;
  214. debugf0("%s()\n", __func__);
  215. if (i82860_pci)
  216. edac_pci_release_generic_ctl(i82860_pci);
  217. if ((mci = edac_mc_del_mc(&pdev->dev)) == NULL)
  218. return;
  219. edac_mc_free(mci);
  220. }
  221. static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
  222. {
  223. PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  224. I82860},
  225. {
  226. 0,
  227. } /* 0 terminated list. */
  228. };
  229. MODULE_DEVICE_TABLE(pci, i82860_pci_tbl);
  230. static struct pci_driver i82860_driver = {
  231. .name = EDAC_MOD_STR,
  232. .probe = i82860_init_one,
  233. .remove = __devexit_p(i82860_remove_one),
  234. .id_table = i82860_pci_tbl,
  235. };
  236. static int __init i82860_init(void)
  237. {
  238. int pci_rc;
  239. debugf3("%s()\n", __func__);
  240. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  241. opstate_init();
  242. if ((pci_rc = pci_register_driver(&i82860_driver)) < 0)
  243. goto fail0;
  244. if (!mci_pdev) {
  245. mci_pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  246. PCI_DEVICE_ID_INTEL_82860_0, NULL);
  247. if (mci_pdev == NULL) {
  248. debugf0("860 pci_get_device fail\n");
  249. pci_rc = -ENODEV;
  250. goto fail1;
  251. }
  252. pci_rc = i82860_init_one(mci_pdev, i82860_pci_tbl);
  253. if (pci_rc < 0) {
  254. debugf0("860 init fail\n");
  255. pci_rc = -ENODEV;
  256. goto fail1;
  257. }
  258. }
  259. return 0;
  260. fail1:
  261. pci_unregister_driver(&i82860_driver);
  262. fail0:
  263. if (mci_pdev != NULL)
  264. pci_dev_put(mci_pdev);
  265. return pci_rc;
  266. }
  267. static void __exit i82860_exit(void)
  268. {
  269. debugf3("%s()\n", __func__);
  270. pci_unregister_driver(&i82860_driver);
  271. if (mci_pdev != NULL)
  272. pci_dev_put(mci_pdev);
  273. }
  274. module_init(i82860_init);
  275. module_exit(i82860_exit);
  276. MODULE_LICENSE("GPL");
  277. MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com) "
  278. "Ben Woodard <woodard@redhat.com>");
  279. MODULE_DESCRIPTION("ECC support for Intel 82860 memory hub controllers");
  280. module_param(edac_op_state, int, 0444);
  281. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");