i82860_edac.c 7.7 KB

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