mv64x60_edac.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. /*
  2. * Marvell MV64x60 Memory Controller kernel module for PPC platforms
  3. *
  4. * Author: Dave Jiang <djiang@mvista.com>
  5. *
  6. * 2006-2007 (c) MontaVista Software, Inc. This file is licensed under
  7. * the terms of the GNU General Public License version 2. This program
  8. * is licensed "as is" without any warranty of any kind, whether express
  9. * or implied.
  10. *
  11. */
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/slab.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/io.h>
  17. #include <linux/edac.h>
  18. #include "edac_core.h"
  19. #include "edac_module.h"
  20. #include "mv64x60_edac.h"
  21. static const char *mv64x60_ctl_name = "MV64x60";
  22. static int edac_dev_idx;
  23. static int edac_pci_idx;
  24. static int edac_mc_idx;
  25. /*********************** PCI err device **********************************/
  26. #ifdef CONFIG_PCI
  27. static void mv64x60_pci_check(struct edac_pci_ctl_info *pci)
  28. {
  29. struct mv64x60_pci_pdata *pdata = pci->pvt_info;
  30. u32 cause;
  31. cause = in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_CAUSE);
  32. if (!cause)
  33. return;
  34. printk(KERN_ERR "Error in PCI %d Interface\n", pdata->pci_hose);
  35. printk(KERN_ERR "Cause register: 0x%08x\n", cause);
  36. printk(KERN_ERR "Address Low: 0x%08x\n",
  37. in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_ADDR_LO));
  38. printk(KERN_ERR "Address High: 0x%08x\n",
  39. in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_ADDR_HI));
  40. printk(KERN_ERR "Attribute: 0x%08x\n",
  41. in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_ATTR));
  42. printk(KERN_ERR "Command: 0x%08x\n",
  43. in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_CMD));
  44. out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_CAUSE, ~cause);
  45. if (cause & MV64X60_PCI_PE_MASK)
  46. edac_pci_handle_pe(pci, pci->ctl_name);
  47. if (!(cause & MV64X60_PCI_PE_MASK))
  48. edac_pci_handle_npe(pci, pci->ctl_name);
  49. }
  50. static irqreturn_t mv64x60_pci_isr(int irq, void *dev_id)
  51. {
  52. struct edac_pci_ctl_info *pci = dev_id;
  53. struct mv64x60_pci_pdata *pdata = pci->pvt_info;
  54. u32 val;
  55. val = in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_CAUSE);
  56. if (!val)
  57. return IRQ_NONE;
  58. mv64x60_pci_check(pci);
  59. return IRQ_HANDLED;
  60. }
  61. static int __devinit mv64x60_pci_err_probe(struct platform_device *pdev)
  62. {
  63. struct edac_pci_ctl_info *pci;
  64. struct mv64x60_pci_pdata *pdata;
  65. struct resource *r;
  66. int res = 0;
  67. if (!devres_open_group(&pdev->dev, mv64x60_pci_err_probe, GFP_KERNEL))
  68. return -ENOMEM;
  69. pci = edac_pci_alloc_ctl_info(sizeof(*pdata), "mv64x60_pci_err");
  70. if (!pci)
  71. return -ENOMEM;
  72. pdata = pci->pvt_info;
  73. pdata->pci_hose = pdev->id;
  74. pdata->name = "mpc85xx_pci_err";
  75. pdata->irq = NO_IRQ;
  76. platform_set_drvdata(pdev, pci);
  77. pci->dev = &pdev->dev;
  78. pci->dev_name = pdev->dev.bus_id;
  79. pci->mod_name = EDAC_MOD_STR;
  80. pci->ctl_name = pdata->name;
  81. if (edac_op_state == EDAC_OPSTATE_POLL)
  82. pci->edac_check = mv64x60_pci_check;
  83. pdata->edac_idx = edac_pci_idx++;
  84. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  85. if (!r) {
  86. printk(KERN_ERR "%s: Unable to get resource for "
  87. "PCI err regs\n", __func__);
  88. res = -ENOENT;
  89. goto err;
  90. }
  91. if (!devm_request_mem_region(&pdev->dev,
  92. r->start,
  93. r->end - r->start + 1,
  94. pdata->name)) {
  95. printk(KERN_ERR "%s: Error while requesting mem region\n",
  96. __func__);
  97. res = -EBUSY;
  98. goto err;
  99. }
  100. pdata->pci_vbase = devm_ioremap(&pdev->dev,
  101. r->start,
  102. r->end - r->start + 1);
  103. if (!pdata->pci_vbase) {
  104. printk(KERN_ERR "%s: Unable to setup PCI err regs\n", __func__);
  105. res = -ENOMEM;
  106. goto err;
  107. }
  108. out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_CAUSE, 0);
  109. out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_MASK, 0);
  110. out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_MASK,
  111. MV64X60_PCIx_ERR_MASK_VAL);
  112. if (edac_pci_add_device(pci, pdata->edac_idx) > 0) {
  113. debugf3("%s(): failed edac_pci_add_device()\n", __func__);
  114. goto err;
  115. }
  116. if (edac_op_state == EDAC_OPSTATE_INT) {
  117. pdata->irq = platform_get_irq(pdev, 0);
  118. res = devm_request_irq(&pdev->dev,
  119. pdata->irq,
  120. mv64x60_pci_isr,
  121. IRQF_DISABLED,
  122. "[EDAC] PCI err",
  123. pci);
  124. if (res < 0) {
  125. printk(KERN_ERR "%s: Unable to request irq %d for "
  126. "MV64x60 PCI ERR\n", __func__, pdata->irq);
  127. res = -ENODEV;
  128. goto err2;
  129. }
  130. printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for PCI Err\n",
  131. pdata->irq);
  132. }
  133. devres_remove_group(&pdev->dev, mv64x60_pci_err_probe);
  134. /* get this far and it's successful */
  135. debugf3("%s(): success\n", __func__);
  136. return 0;
  137. err2:
  138. edac_pci_del_device(&pdev->dev);
  139. err:
  140. edac_pci_free_ctl_info(pci);
  141. devres_release_group(&pdev->dev, mv64x60_pci_err_probe);
  142. return res;
  143. }
  144. static int mv64x60_pci_err_remove(struct platform_device *pdev)
  145. {
  146. struct edac_pci_ctl_info *pci = platform_get_drvdata(pdev);
  147. debugf0("%s()\n", __func__);
  148. edac_pci_del_device(&pdev->dev);
  149. edac_pci_free_ctl_info(pci);
  150. return 0;
  151. }
  152. static struct platform_driver mv64x60_pci_err_driver = {
  153. .probe = mv64x60_pci_err_probe,
  154. .remove = __devexit_p(mv64x60_pci_err_remove),
  155. .driver = {
  156. .name = "mv64x60_pci_err",
  157. }
  158. };
  159. #endif /* CONFIG_PCI */
  160. /*********************** SRAM err device **********************************/
  161. static void mv64x60_sram_check(struct edac_device_ctl_info *edac_dev)
  162. {
  163. struct mv64x60_sram_pdata *pdata = edac_dev->pvt_info;
  164. u32 cause;
  165. cause = in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_CAUSE);
  166. if (!cause)
  167. return;
  168. printk(KERN_ERR "Error in internal SRAM\n");
  169. printk(KERN_ERR "Cause register: 0x%08x\n", cause);
  170. printk(KERN_ERR "Address Low: 0x%08x\n",
  171. in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_ADDR_LO));
  172. printk(KERN_ERR "Address High: 0x%08x\n",
  173. in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_ADDR_HI));
  174. printk(KERN_ERR "Data Low: 0x%08x\n",
  175. in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_DATA_LO));
  176. printk(KERN_ERR "Data High: 0x%08x\n",
  177. in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_DATA_HI));
  178. printk(KERN_ERR "Parity: 0x%08x\n",
  179. in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_PARITY));
  180. out_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_CAUSE, 0);
  181. edac_device_handle_ue(edac_dev, 0, 0, edac_dev->ctl_name);
  182. }
  183. static irqreturn_t mv64x60_sram_isr(int irq, void *dev_id)
  184. {
  185. struct edac_device_ctl_info *edac_dev = dev_id;
  186. struct mv64x60_sram_pdata *pdata = edac_dev->pvt_info;
  187. u32 cause;
  188. cause = in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_CAUSE);
  189. if (!cause)
  190. return IRQ_NONE;
  191. mv64x60_sram_check(edac_dev);
  192. return IRQ_HANDLED;
  193. }
  194. static int __devinit mv64x60_sram_err_probe(struct platform_device *pdev)
  195. {
  196. struct edac_device_ctl_info *edac_dev;
  197. struct mv64x60_sram_pdata *pdata;
  198. struct resource *r;
  199. int res = 0;
  200. if (!devres_open_group(&pdev->dev, mv64x60_sram_err_probe, GFP_KERNEL))
  201. return -ENOMEM;
  202. edac_dev = edac_device_alloc_ctl_info(sizeof(*pdata),
  203. "sram", 1, NULL, 0, 0, NULL, 0,
  204. edac_dev_idx);
  205. if (!edac_dev) {
  206. devres_release_group(&pdev->dev, mv64x60_sram_err_probe);
  207. return -ENOMEM;
  208. }
  209. pdata = edac_dev->pvt_info;
  210. pdata->name = "mv64x60_sram_err";
  211. pdata->irq = NO_IRQ;
  212. edac_dev->dev = &pdev->dev;
  213. platform_set_drvdata(pdev, edac_dev);
  214. edac_dev->dev_name = pdev->dev.bus_id;
  215. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  216. if (!r) {
  217. printk(KERN_ERR "%s: Unable to get resource for "
  218. "SRAM err regs\n", __func__);
  219. res = -ENOENT;
  220. goto err;
  221. }
  222. if (!devm_request_mem_region(&pdev->dev,
  223. r->start,
  224. r->end - r->start + 1,
  225. pdata->name)) {
  226. printk(KERN_ERR "%s: Error while request mem region\n",
  227. __func__);
  228. res = -EBUSY;
  229. goto err;
  230. }
  231. pdata->sram_vbase = devm_ioremap(&pdev->dev,
  232. r->start,
  233. r->end - r->start + 1);
  234. if (!pdata->sram_vbase) {
  235. printk(KERN_ERR "%s: Unable to setup SRAM err regs\n",
  236. __func__);
  237. res = -ENOMEM;
  238. goto err;
  239. }
  240. /* setup SRAM err registers */
  241. out_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_CAUSE, 0);
  242. edac_dev->mod_name = EDAC_MOD_STR;
  243. edac_dev->ctl_name = pdata->name;
  244. if (edac_op_state == EDAC_OPSTATE_POLL)
  245. edac_dev->edac_check = mv64x60_sram_check;
  246. pdata->edac_idx = edac_dev_idx++;
  247. if (edac_device_add_device(edac_dev) > 0) {
  248. debugf3("%s(): failed edac_device_add_device()\n", __func__);
  249. goto err;
  250. }
  251. if (edac_op_state == EDAC_OPSTATE_INT) {
  252. pdata->irq = platform_get_irq(pdev, 0);
  253. res = devm_request_irq(&pdev->dev,
  254. pdata->irq,
  255. mv64x60_sram_isr,
  256. IRQF_DISABLED,
  257. "[EDAC] SRAM err",
  258. edac_dev);
  259. if (res < 0) {
  260. printk(KERN_ERR
  261. "%s: Unable to request irq %d for "
  262. "MV64x60 SRAM ERR\n", __func__, pdata->irq);
  263. res = -ENODEV;
  264. goto err2;
  265. }
  266. printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for SRAM Err\n",
  267. pdata->irq);
  268. }
  269. devres_remove_group(&pdev->dev, mv64x60_sram_err_probe);
  270. /* get this far and it's successful */
  271. debugf3("%s(): success\n", __func__);
  272. return 0;
  273. err2:
  274. edac_device_del_device(&pdev->dev);
  275. err:
  276. devres_release_group(&pdev->dev, mv64x60_sram_err_probe);
  277. edac_device_free_ctl_info(edac_dev);
  278. return res;
  279. }
  280. static int mv64x60_sram_err_remove(struct platform_device *pdev)
  281. {
  282. struct edac_device_ctl_info *edac_dev = platform_get_drvdata(pdev);
  283. debugf0("%s()\n", __func__);
  284. edac_device_del_device(&pdev->dev);
  285. edac_device_free_ctl_info(edac_dev);
  286. return 0;
  287. }
  288. static struct platform_driver mv64x60_sram_err_driver = {
  289. .probe = mv64x60_sram_err_probe,
  290. .remove = mv64x60_sram_err_remove,
  291. .driver = {
  292. .name = "mv64x60_sram_err",
  293. }
  294. };
  295. /*********************** CPU err device **********************************/
  296. static void mv64x60_cpu_check(struct edac_device_ctl_info *edac_dev)
  297. {
  298. struct mv64x60_cpu_pdata *pdata = edac_dev->pvt_info;
  299. u32 cause;
  300. cause = in_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_CAUSE) &
  301. MV64x60_CPU_CAUSE_MASK;
  302. if (!cause)
  303. return;
  304. printk(KERN_ERR "Error on CPU interface\n");
  305. printk(KERN_ERR "Cause register: 0x%08x\n", cause);
  306. printk(KERN_ERR "Address Low: 0x%08x\n",
  307. in_le32(pdata->cpu_vbase[0] + MV64x60_CPU_ERR_ADDR_LO));
  308. printk(KERN_ERR "Address High: 0x%08x\n",
  309. in_le32(pdata->cpu_vbase[0] + MV64x60_CPU_ERR_ADDR_HI));
  310. printk(KERN_ERR "Data Low: 0x%08x\n",
  311. in_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_DATA_LO));
  312. printk(KERN_ERR "Data High: 0x%08x\n",
  313. in_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_DATA_HI));
  314. printk(KERN_ERR "Parity: 0x%08x\n",
  315. in_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_PARITY));
  316. out_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_CAUSE, 0);
  317. edac_device_handle_ue(edac_dev, 0, 0, edac_dev->ctl_name);
  318. }
  319. static irqreturn_t mv64x60_cpu_isr(int irq, void *dev_id)
  320. {
  321. struct edac_device_ctl_info *edac_dev = dev_id;
  322. struct mv64x60_cpu_pdata *pdata = edac_dev->pvt_info;
  323. u32 cause;
  324. cause = in_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_CAUSE) &
  325. MV64x60_CPU_CAUSE_MASK;
  326. if (!cause)
  327. return IRQ_NONE;
  328. mv64x60_cpu_check(edac_dev);
  329. return IRQ_HANDLED;
  330. }
  331. static int __devinit mv64x60_cpu_err_probe(struct platform_device *pdev)
  332. {
  333. struct edac_device_ctl_info *edac_dev;
  334. struct resource *r;
  335. struct mv64x60_cpu_pdata *pdata;
  336. int res = 0;
  337. if (!devres_open_group(&pdev->dev, mv64x60_cpu_err_probe, GFP_KERNEL))
  338. return -ENOMEM;
  339. edac_dev = edac_device_alloc_ctl_info(sizeof(*pdata),
  340. "cpu", 1, NULL, 0, 0, NULL, 0,
  341. edac_dev_idx);
  342. if (!edac_dev) {
  343. devres_release_group(&pdev->dev, mv64x60_cpu_err_probe);
  344. return -ENOMEM;
  345. }
  346. pdata = edac_dev->pvt_info;
  347. pdata->name = "mv64x60_cpu_err";
  348. pdata->irq = NO_IRQ;
  349. edac_dev->dev = &pdev->dev;
  350. platform_set_drvdata(pdev, edac_dev);
  351. edac_dev->dev_name = pdev->dev.bus_id;
  352. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  353. if (!r) {
  354. printk(KERN_ERR "%s: Unable to get resource for "
  355. "CPU err regs\n", __func__);
  356. res = -ENOENT;
  357. goto err;
  358. }
  359. if (!devm_request_mem_region(&pdev->dev,
  360. r->start,
  361. r->end - r->start + 1,
  362. pdata->name)) {
  363. printk(KERN_ERR "%s: Error while requesting mem region\n",
  364. __func__);
  365. res = -EBUSY;
  366. goto err;
  367. }
  368. pdata->cpu_vbase[0] = devm_ioremap(&pdev->dev,
  369. r->start,
  370. r->end - r->start + 1);
  371. if (!pdata->cpu_vbase[0]) {
  372. printk(KERN_ERR "%s: Unable to setup CPU err regs\n", __func__);
  373. res = -ENOMEM;
  374. goto err;
  375. }
  376. r = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  377. if (!r) {
  378. printk(KERN_ERR "%s: Unable to get resource for "
  379. "CPU err regs\n", __func__);
  380. res = -ENOENT;
  381. goto err;
  382. }
  383. if (!devm_request_mem_region(&pdev->dev,
  384. r->start,
  385. r->end - r->start + 1,
  386. pdata->name)) {
  387. printk(KERN_ERR "%s: Error while requesting mem region\n",
  388. __func__);
  389. res = -EBUSY;
  390. goto err;
  391. }
  392. pdata->cpu_vbase[1] = devm_ioremap(&pdev->dev,
  393. r->start,
  394. r->end - r->start + 1);
  395. if (!pdata->cpu_vbase[1]) {
  396. printk(KERN_ERR "%s: Unable to setup CPU err regs\n", __func__);
  397. res = -ENOMEM;
  398. goto err;
  399. }
  400. /* setup CPU err registers */
  401. out_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_CAUSE, 0);
  402. out_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_MASK, 0);
  403. out_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_MASK, 0x000000ff);
  404. edac_dev->mod_name = EDAC_MOD_STR;
  405. edac_dev->ctl_name = pdata->name;
  406. if (edac_op_state == EDAC_OPSTATE_POLL)
  407. edac_dev->edac_check = mv64x60_cpu_check;
  408. pdata->edac_idx = edac_dev_idx++;
  409. if (edac_device_add_device(edac_dev) > 0) {
  410. debugf3("%s(): failed edac_device_add_device()\n", __func__);
  411. goto err;
  412. }
  413. if (edac_op_state == EDAC_OPSTATE_INT) {
  414. pdata->irq = platform_get_irq(pdev, 0);
  415. res = devm_request_irq(&pdev->dev,
  416. pdata->irq,
  417. mv64x60_cpu_isr,
  418. IRQF_DISABLED,
  419. "[EDAC] CPU err",
  420. edac_dev);
  421. if (res < 0) {
  422. printk(KERN_ERR
  423. "%s: Unable to request irq %d for MV64x60 "
  424. "CPU ERR\n", __func__, pdata->irq);
  425. res = -ENODEV;
  426. goto err2;
  427. }
  428. printk(KERN_INFO EDAC_MOD_STR
  429. " acquired irq %d for CPU Err\n", pdata->irq);
  430. }
  431. devres_remove_group(&pdev->dev, mv64x60_cpu_err_probe);
  432. /* get this far and it's successful */
  433. debugf3("%s(): success\n", __func__);
  434. return 0;
  435. err2:
  436. edac_device_del_device(&pdev->dev);
  437. err:
  438. devres_release_group(&pdev->dev, mv64x60_cpu_err_probe);
  439. edac_device_free_ctl_info(edac_dev);
  440. return res;
  441. }
  442. static int mv64x60_cpu_err_remove(struct platform_device *pdev)
  443. {
  444. struct edac_device_ctl_info *edac_dev = platform_get_drvdata(pdev);
  445. debugf0("%s()\n", __func__);
  446. edac_device_del_device(&pdev->dev);
  447. edac_device_free_ctl_info(edac_dev);
  448. return 0;
  449. }
  450. static struct platform_driver mv64x60_cpu_err_driver = {
  451. .probe = mv64x60_cpu_err_probe,
  452. .remove = mv64x60_cpu_err_remove,
  453. .driver = {
  454. .name = "mv64x60_cpu_err",
  455. }
  456. };
  457. /*********************** DRAM err device **********************************/
  458. static void mv64x60_mc_check(struct mem_ctl_info *mci)
  459. {
  460. struct mv64x60_mc_pdata *pdata = mci->pvt_info;
  461. u32 reg;
  462. u32 err_addr;
  463. u32 sdram_ecc;
  464. u32 comp_ecc;
  465. u32 syndrome;
  466. reg = in_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ADDR);
  467. if (!reg)
  468. return;
  469. err_addr = reg & ~0x3;
  470. sdram_ecc = in_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ECC_RCVD);
  471. comp_ecc = in_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ECC_CALC);
  472. syndrome = sdram_ecc ^ comp_ecc;
  473. /* first bit clear in ECC Err Reg, 1 bit error, correctable by HW */
  474. if (!(reg & 0x1))
  475. edac_mc_handle_ce(mci, err_addr >> PAGE_SHIFT,
  476. err_addr & PAGE_MASK, syndrome, 0, 0,
  477. mci->ctl_name);
  478. else /* 2 bit error, UE */
  479. edac_mc_handle_ue(mci, err_addr >> PAGE_SHIFT,
  480. err_addr & PAGE_MASK, 0, mci->ctl_name);
  481. /* clear the error */
  482. out_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ADDR, 0);
  483. }
  484. static irqreturn_t mv64x60_mc_isr(int irq, void *dev_id)
  485. {
  486. struct mem_ctl_info *mci = dev_id;
  487. struct mv64x60_mc_pdata *pdata = mci->pvt_info;
  488. u32 reg;
  489. reg = in_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ADDR);
  490. if (!reg)
  491. return IRQ_NONE;
  492. /* writing 0's to the ECC err addr in check function clears irq */
  493. mv64x60_mc_check(mci);
  494. return IRQ_HANDLED;
  495. }
  496. static void get_total_mem(struct mv64x60_mc_pdata *pdata)
  497. {
  498. struct device_node *np = NULL;
  499. const unsigned int *reg;
  500. np = of_find_node_by_type(NULL, "memory");
  501. if (!np)
  502. return;
  503. reg = get_property(np, "reg", NULL);
  504. pdata->total_mem = reg[1];
  505. }
  506. static void mv64x60_init_csrows(struct mem_ctl_info *mci,
  507. struct mv64x60_mc_pdata *pdata)
  508. {
  509. struct csrow_info *csrow;
  510. u32 devtype;
  511. u32 ctl;
  512. get_total_mem(pdata);
  513. ctl = in_le32(pdata->mc_vbase + MV64X60_SDRAM_CONFIG);
  514. csrow = &mci->csrows[0];
  515. csrow->first_page = 0;
  516. csrow->nr_pages = pdata->total_mem >> PAGE_SHIFT;
  517. csrow->last_page = csrow->first_page + csrow->nr_pages - 1;
  518. csrow->grain = 8;
  519. csrow->mtype = (ctl & MV64X60_SDRAM_REGISTERED) ? MEM_RDDR : MEM_DDR;
  520. devtype = (ctl >> 20) & 0x3;
  521. switch (devtype) {
  522. case 0x0:
  523. csrow->dtype = DEV_X32;
  524. break;
  525. case 0x2: /* could be X8 too, but no way to tell */
  526. csrow->dtype = DEV_X16;
  527. break;
  528. case 0x3:
  529. csrow->dtype = DEV_X4;
  530. break;
  531. default:
  532. csrow->dtype = DEV_UNKNOWN;
  533. break;
  534. }
  535. csrow->edac_mode = EDAC_SECDED;
  536. }
  537. static int __devinit mv64x60_mc_err_probe(struct platform_device *pdev)
  538. {
  539. struct mem_ctl_info *mci;
  540. struct mv64x60_mc_pdata *pdata;
  541. struct resource *r;
  542. u32 ctl;
  543. int res = 0;
  544. if (!devres_open_group(&pdev->dev, mv64x60_mc_err_probe, GFP_KERNEL))
  545. return -ENOMEM;
  546. mci = edac_mc_alloc(sizeof(struct mv64x60_mc_pdata), 1, 1, edac_mc_idx);
  547. if (!mci) {
  548. printk(KERN_ERR "%s: No memory for CPU err\n", __func__);
  549. devres_release_group(&pdev->dev, mv64x60_mc_err_probe);
  550. return -ENOMEM;
  551. }
  552. pdata = mci->pvt_info;
  553. mci->dev = &pdev->dev;
  554. platform_set_drvdata(pdev, mci);
  555. pdata->name = "mv64x60_mc_err";
  556. pdata->irq = NO_IRQ;
  557. mci->dev_name = pdev->dev.bus_id;
  558. pdata->edac_idx = edac_mc_idx++;
  559. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  560. if (!r) {
  561. printk(KERN_ERR "%s: Unable to get resource for "
  562. "MC err regs\n", __func__);
  563. res = -ENOENT;
  564. goto err;
  565. }
  566. if (!devm_request_mem_region(&pdev->dev,
  567. r->start,
  568. r->end - r->start + 1,
  569. pdata->name)) {
  570. printk(KERN_ERR "%s: Error while requesting mem region\n",
  571. __func__);
  572. res = -EBUSY;
  573. goto err;
  574. }
  575. pdata->mc_vbase = devm_ioremap(&pdev->dev,
  576. r->start,
  577. r->end - r->start + 1);
  578. if (!pdata->mc_vbase) {
  579. printk(KERN_ERR "%s: Unable to setup MC err regs\n", __func__);
  580. res = -ENOMEM;
  581. goto err;
  582. }
  583. ctl = in_le32(pdata->mc_vbase + MV64X60_SDRAM_CONFIG);
  584. if (!(ctl & MV64X60_SDRAM_ECC)) {
  585. /* Non-ECC RAM? */
  586. printk(KERN_WARNING "%s: No ECC DIMMs discovered\n", __func__);
  587. res = -ENODEV;
  588. goto err2;
  589. }
  590. debugf3("%s(): init mci\n", __func__);
  591. mci->mtype_cap = MEM_FLAG_RDDR | MEM_FLAG_DDR;
  592. mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
  593. mci->edac_cap = EDAC_FLAG_SECDED;
  594. mci->mod_name = EDAC_MOD_STR;
  595. mci->mod_ver = MV64x60_REVISION;
  596. mci->ctl_name = mv64x60_ctl_name;
  597. if (edac_op_state == EDAC_OPSTATE_POLL)
  598. mci->edac_check = mv64x60_mc_check;
  599. mci->ctl_page_to_phys = NULL;
  600. mci->scrub_mode = SCRUB_SW_SRC;
  601. mv64x60_init_csrows(mci, pdata);
  602. /* setup MC registers */
  603. out_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ADDR, 0);
  604. ctl = in_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ECC_CNTL);
  605. ctl = (ctl & 0xff00ffff) | 0x10000;
  606. out_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ECC_CNTL, ctl);
  607. if (edac_mc_add_mc(mci)) {
  608. debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
  609. goto err;
  610. }
  611. if (edac_op_state == EDAC_OPSTATE_INT) {
  612. /* acquire interrupt that reports errors */
  613. pdata->irq = platform_get_irq(pdev, 0);
  614. res = devm_request_irq(&pdev->dev,
  615. pdata->irq,
  616. mv64x60_mc_isr,
  617. IRQF_DISABLED,
  618. "[EDAC] MC err",
  619. mci);
  620. if (res < 0) {
  621. printk(KERN_ERR "%s: Unable to request irq %d for "
  622. "MV64x60 DRAM ERR\n", __func__, pdata->irq);
  623. res = -ENODEV;
  624. goto err2;
  625. }
  626. printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for MC Err\n",
  627. pdata->irq);
  628. }
  629. /* get this far and it's successful */
  630. debugf3("%s(): success\n", __func__);
  631. return 0;
  632. err2:
  633. edac_mc_del_mc(&pdev->dev);
  634. err:
  635. devres_release_group(&pdev->dev, mv64x60_mc_err_probe);
  636. edac_mc_free(mci);
  637. return res;
  638. }
  639. static int mv64x60_mc_err_remove(struct platform_device *pdev)
  640. {
  641. struct mem_ctl_info *mci = platform_get_drvdata(pdev);
  642. debugf0("%s()\n", __func__);
  643. edac_mc_del_mc(&pdev->dev);
  644. edac_mc_free(mci);
  645. return 0;
  646. }
  647. static struct platform_driver mv64x60_mc_err_driver = {
  648. .probe = mv64x60_mc_err_probe,
  649. .remove = mv64x60_mc_err_remove,
  650. .driver = {
  651. .name = "mv64x60_mc_err",
  652. }
  653. };
  654. static int __init mv64x60_edac_init(void)
  655. {
  656. int ret = 0;
  657. printk(KERN_INFO "Marvell MV64x60 EDAC driver " MV64x60_REVISION "\n");
  658. printk(KERN_INFO "\t(C) 2006-2007 MontaVista Software\n");
  659. /* make sure error reporting method is sane */
  660. switch (edac_op_state) {
  661. case EDAC_OPSTATE_POLL:
  662. case EDAC_OPSTATE_INT:
  663. break;
  664. default:
  665. edac_op_state = EDAC_OPSTATE_INT;
  666. break;
  667. }
  668. ret = platform_driver_register(&mv64x60_mc_err_driver);
  669. if (ret)
  670. printk(KERN_WARNING EDAC_MOD_STR "MC err failed to register\n");
  671. ret = platform_driver_register(&mv64x60_cpu_err_driver);
  672. if (ret)
  673. printk(KERN_WARNING EDAC_MOD_STR
  674. "CPU err failed to register\n");
  675. ret = platform_driver_register(&mv64x60_sram_err_driver);
  676. if (ret)
  677. printk(KERN_WARNING EDAC_MOD_STR
  678. "SRAM err failed to register\n");
  679. #ifdef CONFIG_PCI
  680. ret = platform_driver_register(&mv64x60_pci_err_driver);
  681. if (ret)
  682. printk(KERN_WARNING EDAC_MOD_STR
  683. "PCI err failed to register\n");
  684. #endif
  685. return ret;
  686. }
  687. module_init(mv64x60_edac_init);
  688. static void __exit mv64x60_edac_exit(void)
  689. {
  690. #ifdef CONFIG_PCI
  691. platform_driver_unregister(&mv64x60_pci_err_driver);
  692. #endif
  693. platform_driver_unregister(&mv64x60_sram_err_driver);
  694. platform_driver_unregister(&mv64x60_cpu_err_driver);
  695. platform_driver_unregister(&mv64x60_mc_err_driver);
  696. }
  697. module_exit(mv64x60_edac_exit);
  698. MODULE_LICENSE("GPL");
  699. MODULE_AUTHOR("Montavista Software, Inc.");
  700. module_param(edac_op_state, int, 0444);
  701. MODULE_PARM_DESC(edac_op_state,
  702. "EDAC Error Reporting state: 0=Poll, 2=Interrupt");