mpc85xx_edac.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  1. /*
  2. * Freescale MPC85xx Memory Controller kernel module
  3. *
  4. * Parts Copyrighted (c) 2013 by Freescale Semiconductor, Inc.
  5. *
  6. * Author: Dave Jiang <djiang@mvista.com>
  7. *
  8. * 2006-2007 (c) MontaVista Software, Inc. This file is licensed under
  9. * the terms of the GNU General Public License version 2. This program
  10. * is licensed "as is" without any warranty of any kind, whether express
  11. * or implied.
  12. *
  13. */
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/ctype.h>
  18. #include <linux/io.h>
  19. #include <linux/mod_devicetable.h>
  20. #include <linux/edac.h>
  21. #include <linux/smp.h>
  22. #include <linux/gfp.h>
  23. #include <linux/of_platform.h>
  24. #include <linux/of_device.h>
  25. #include "edac_module.h"
  26. #include "edac_core.h"
  27. #include "mpc85xx_edac.h"
  28. static int edac_dev_idx;
  29. #ifdef CONFIG_PCI
  30. static int edac_pci_idx;
  31. #endif
  32. static int edac_mc_idx;
  33. static u32 orig_ddr_err_disable;
  34. static u32 orig_ddr_err_sbe;
  35. /*
  36. * PCI Err defines
  37. */
  38. #ifdef CONFIG_PCI
  39. static u32 orig_pci_err_cap_dr;
  40. static u32 orig_pci_err_en;
  41. #endif
  42. static u32 orig_l2_err_disable;
  43. #ifdef CONFIG_FSL_SOC_BOOKE
  44. static u32 orig_hid1[2];
  45. #endif
  46. /************************ MC SYSFS parts ***********************************/
  47. #define to_mci(k) container_of(k, struct mem_ctl_info, dev)
  48. static ssize_t mpc85xx_mc_inject_data_hi_show(struct device *dev,
  49. struct device_attribute *mattr,
  50. char *data)
  51. {
  52. struct mem_ctl_info *mci = to_mci(dev);
  53. struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
  54. return sprintf(data, "0x%08x",
  55. in_be32(pdata->mc_vbase +
  56. MPC85XX_MC_DATA_ERR_INJECT_HI));
  57. }
  58. static ssize_t mpc85xx_mc_inject_data_lo_show(struct device *dev,
  59. struct device_attribute *mattr,
  60. char *data)
  61. {
  62. struct mem_ctl_info *mci = to_mci(dev);
  63. struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
  64. return sprintf(data, "0x%08x",
  65. in_be32(pdata->mc_vbase +
  66. MPC85XX_MC_DATA_ERR_INJECT_LO));
  67. }
  68. static ssize_t mpc85xx_mc_inject_ctrl_show(struct device *dev,
  69. struct device_attribute *mattr,
  70. char *data)
  71. {
  72. struct mem_ctl_info *mci = to_mci(dev);
  73. struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
  74. return sprintf(data, "0x%08x",
  75. in_be32(pdata->mc_vbase + MPC85XX_MC_ECC_ERR_INJECT));
  76. }
  77. static ssize_t mpc85xx_mc_inject_data_hi_store(struct device *dev,
  78. struct device_attribute *mattr,
  79. const char *data, size_t count)
  80. {
  81. struct mem_ctl_info *mci = to_mci(dev);
  82. struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
  83. if (isdigit(*data)) {
  84. out_be32(pdata->mc_vbase + MPC85XX_MC_DATA_ERR_INJECT_HI,
  85. simple_strtoul(data, NULL, 0));
  86. return count;
  87. }
  88. return 0;
  89. }
  90. static ssize_t mpc85xx_mc_inject_data_lo_store(struct device *dev,
  91. struct device_attribute *mattr,
  92. const char *data, size_t count)
  93. {
  94. struct mem_ctl_info *mci = to_mci(dev);
  95. struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
  96. if (isdigit(*data)) {
  97. out_be32(pdata->mc_vbase + MPC85XX_MC_DATA_ERR_INJECT_LO,
  98. simple_strtoul(data, NULL, 0));
  99. return count;
  100. }
  101. return 0;
  102. }
  103. static ssize_t mpc85xx_mc_inject_ctrl_store(struct device *dev,
  104. struct device_attribute *mattr,
  105. const char *data, size_t count)
  106. {
  107. struct mem_ctl_info *mci = to_mci(dev);
  108. struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
  109. if (isdigit(*data)) {
  110. out_be32(pdata->mc_vbase + MPC85XX_MC_ECC_ERR_INJECT,
  111. simple_strtoul(data, NULL, 0));
  112. return count;
  113. }
  114. return 0;
  115. }
  116. DEVICE_ATTR(inject_data_hi, S_IRUGO | S_IWUSR,
  117. mpc85xx_mc_inject_data_hi_show, mpc85xx_mc_inject_data_hi_store);
  118. DEVICE_ATTR(inject_data_lo, S_IRUGO | S_IWUSR,
  119. mpc85xx_mc_inject_data_lo_show, mpc85xx_mc_inject_data_lo_store);
  120. DEVICE_ATTR(inject_ctrl, S_IRUGO | S_IWUSR,
  121. mpc85xx_mc_inject_ctrl_show, mpc85xx_mc_inject_ctrl_store);
  122. static struct attribute *mpc85xx_dev_attrs[] = {
  123. &dev_attr_inject_data_hi.attr,
  124. &dev_attr_inject_data_lo.attr,
  125. &dev_attr_inject_ctrl.attr,
  126. NULL
  127. };
  128. ATTRIBUTE_GROUPS(mpc85xx_dev);
  129. /**************************** PCI Err device ***************************/
  130. #ifdef CONFIG_PCI
  131. static void mpc85xx_pci_check(struct edac_pci_ctl_info *pci)
  132. {
  133. struct mpc85xx_pci_pdata *pdata = pci->pvt_info;
  134. u32 err_detect;
  135. err_detect = in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR);
  136. /* master aborts can happen during PCI config cycles */
  137. if (!(err_detect & ~(PCI_EDE_MULTI_ERR | PCI_EDE_MST_ABRT))) {
  138. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR, err_detect);
  139. return;
  140. }
  141. printk(KERN_ERR "PCI error(s) detected\n");
  142. printk(KERN_ERR "PCI/X ERR_DR register: %#08x\n", err_detect);
  143. printk(KERN_ERR "PCI/X ERR_ATTRIB register: %#08x\n",
  144. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_ATTRIB));
  145. printk(KERN_ERR "PCI/X ERR_ADDR register: %#08x\n",
  146. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_ADDR));
  147. printk(KERN_ERR "PCI/X ERR_EXT_ADDR register: %#08x\n",
  148. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EXT_ADDR));
  149. printk(KERN_ERR "PCI/X ERR_DL register: %#08x\n",
  150. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DL));
  151. printk(KERN_ERR "PCI/X ERR_DH register: %#08x\n",
  152. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DH));
  153. /* clear error bits */
  154. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR, err_detect);
  155. if (err_detect & PCI_EDE_PERR_MASK)
  156. edac_pci_handle_pe(pci, pci->ctl_name);
  157. if ((err_detect & ~PCI_EDE_MULTI_ERR) & ~PCI_EDE_PERR_MASK)
  158. edac_pci_handle_npe(pci, pci->ctl_name);
  159. }
  160. static void mpc85xx_pcie_check(struct edac_pci_ctl_info *pci)
  161. {
  162. struct mpc85xx_pci_pdata *pdata = pci->pvt_info;
  163. u32 err_detect;
  164. err_detect = in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR);
  165. pr_err("PCIe error(s) detected\n");
  166. pr_err("PCIe ERR_DR register: 0x%08x\n", err_detect);
  167. pr_err("PCIe ERR_CAP_STAT register: 0x%08x\n",
  168. in_be32(pdata->pci_vbase + MPC85XX_PCI_GAS_TIMR));
  169. pr_err("PCIe ERR_CAP_R0 register: 0x%08x\n",
  170. in_be32(pdata->pci_vbase + MPC85XX_PCIE_ERR_CAP_R0));
  171. pr_err("PCIe ERR_CAP_R1 register: 0x%08x\n",
  172. in_be32(pdata->pci_vbase + MPC85XX_PCIE_ERR_CAP_R1));
  173. pr_err("PCIe ERR_CAP_R2 register: 0x%08x\n",
  174. in_be32(pdata->pci_vbase + MPC85XX_PCIE_ERR_CAP_R2));
  175. pr_err("PCIe ERR_CAP_R3 register: 0x%08x\n",
  176. in_be32(pdata->pci_vbase + MPC85XX_PCIE_ERR_CAP_R3));
  177. /* clear error bits */
  178. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR, err_detect);
  179. }
  180. static int mpc85xx_pcie_find_capability(struct device_node *np)
  181. {
  182. struct pci_controller *hose;
  183. if (!np)
  184. return -EINVAL;
  185. hose = pci_find_hose_for_OF_device(np);
  186. return early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP);
  187. }
  188. static irqreturn_t mpc85xx_pci_isr(int irq, void *dev_id)
  189. {
  190. struct edac_pci_ctl_info *pci = dev_id;
  191. struct mpc85xx_pci_pdata *pdata = pci->pvt_info;
  192. u32 err_detect;
  193. err_detect = in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR);
  194. if (!err_detect)
  195. return IRQ_NONE;
  196. if (pdata->is_pcie)
  197. mpc85xx_pcie_check(pci);
  198. else
  199. mpc85xx_pci_check(pci);
  200. return IRQ_HANDLED;
  201. }
  202. int mpc85xx_pci_err_probe(struct platform_device *op)
  203. {
  204. struct edac_pci_ctl_info *pci;
  205. struct mpc85xx_pci_pdata *pdata;
  206. struct resource r;
  207. int res = 0;
  208. if (!devres_open_group(&op->dev, mpc85xx_pci_err_probe, GFP_KERNEL))
  209. return -ENOMEM;
  210. pci = edac_pci_alloc_ctl_info(sizeof(*pdata), "mpc85xx_pci_err");
  211. if (!pci)
  212. return -ENOMEM;
  213. /* make sure error reporting method is sane */
  214. switch (edac_op_state) {
  215. case EDAC_OPSTATE_POLL:
  216. case EDAC_OPSTATE_INT:
  217. break;
  218. default:
  219. edac_op_state = EDAC_OPSTATE_INT;
  220. break;
  221. }
  222. pdata = pci->pvt_info;
  223. pdata->name = "mpc85xx_pci_err";
  224. pdata->irq = NO_IRQ;
  225. if (mpc85xx_pcie_find_capability(op->dev.of_node) > 0)
  226. pdata->is_pcie = true;
  227. dev_set_drvdata(&op->dev, pci);
  228. pci->dev = &op->dev;
  229. pci->mod_name = EDAC_MOD_STR;
  230. pci->ctl_name = pdata->name;
  231. pci->dev_name = dev_name(&op->dev);
  232. if (edac_op_state == EDAC_OPSTATE_POLL) {
  233. if (pdata->is_pcie)
  234. pci->edac_check = mpc85xx_pcie_check;
  235. else
  236. pci->edac_check = mpc85xx_pci_check;
  237. }
  238. pdata->edac_idx = edac_pci_idx++;
  239. res = of_address_to_resource(op->dev.of_node, 0, &r);
  240. if (res) {
  241. printk(KERN_ERR "%s: Unable to get resource for "
  242. "PCI err regs\n", __func__);
  243. goto err;
  244. }
  245. /* we only need the error registers */
  246. r.start += 0xe00;
  247. if (!devm_request_mem_region(&op->dev, r.start, resource_size(&r),
  248. pdata->name)) {
  249. printk(KERN_ERR "%s: Error while requesting mem region\n",
  250. __func__);
  251. res = -EBUSY;
  252. goto err;
  253. }
  254. pdata->pci_vbase = devm_ioremap(&op->dev, r.start, resource_size(&r));
  255. if (!pdata->pci_vbase) {
  256. printk(KERN_ERR "%s: Unable to setup PCI err regs\n", __func__);
  257. res = -ENOMEM;
  258. goto err;
  259. }
  260. if (pdata->is_pcie) {
  261. orig_pci_err_cap_dr =
  262. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_ADDR);
  263. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_ADDR, ~0);
  264. orig_pci_err_en =
  265. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN);
  266. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN, 0);
  267. } else {
  268. orig_pci_err_cap_dr =
  269. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_CAP_DR);
  270. /* PCI master abort is expected during config cycles */
  271. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_CAP_DR, 0x40);
  272. orig_pci_err_en =
  273. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN);
  274. /* disable master abort reporting */
  275. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN, ~0x40);
  276. }
  277. /* clear error bits */
  278. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR, ~0);
  279. if (edac_pci_add_device(pci, pdata->edac_idx) > 0) {
  280. edac_dbg(3, "failed edac_pci_add_device()\n");
  281. goto err;
  282. }
  283. if (edac_op_state == EDAC_OPSTATE_INT) {
  284. pdata->irq = irq_of_parse_and_map(op->dev.of_node, 0);
  285. res = devm_request_irq(&op->dev, pdata->irq,
  286. mpc85xx_pci_isr,
  287. IRQF_SHARED,
  288. "[EDAC] PCI err", pci);
  289. if (res < 0) {
  290. printk(KERN_ERR
  291. "%s: Unable to request irq %d for "
  292. "MPC85xx PCI err\n", __func__, pdata->irq);
  293. irq_dispose_mapping(pdata->irq);
  294. res = -ENODEV;
  295. goto err2;
  296. }
  297. printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for PCI Err\n",
  298. pdata->irq);
  299. }
  300. if (pdata->is_pcie) {
  301. /*
  302. * Enable all PCIe error interrupt & error detect except invalid
  303. * PEX_CONFIG_ADDR/PEX_CONFIG_DATA access interrupt generation
  304. * enable bit and invalid PEX_CONFIG_ADDR/PEX_CONFIG_DATA access
  305. * detection enable bit. Because PCIe bus code to initialize and
  306. * configure these PCIe devices on booting will use some invalid
  307. * PEX_CONFIG_ADDR/PEX_CONFIG_DATA, edac driver prints the much
  308. * notice information. So disable this detect to fix ugly print.
  309. */
  310. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN, ~0
  311. & ~PEX_ERR_ICCAIE_EN_BIT);
  312. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_ADDR, 0
  313. | PEX_ERR_ICCAD_DISR_BIT);
  314. }
  315. devres_remove_group(&op->dev, mpc85xx_pci_err_probe);
  316. edac_dbg(3, "success\n");
  317. printk(KERN_INFO EDAC_MOD_STR " PCI err registered\n");
  318. return 0;
  319. err2:
  320. edac_pci_del_device(&op->dev);
  321. err:
  322. edac_pci_free_ctl_info(pci);
  323. devres_release_group(&op->dev, mpc85xx_pci_err_probe);
  324. return res;
  325. }
  326. EXPORT_SYMBOL(mpc85xx_pci_err_probe);
  327. #endif /* CONFIG_PCI */
  328. /**************************** L2 Err device ***************************/
  329. /************************ L2 SYSFS parts ***********************************/
  330. static ssize_t mpc85xx_l2_inject_data_hi_show(struct edac_device_ctl_info
  331. *edac_dev, char *data)
  332. {
  333. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  334. return sprintf(data, "0x%08x",
  335. in_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJHI));
  336. }
  337. static ssize_t mpc85xx_l2_inject_data_lo_show(struct edac_device_ctl_info
  338. *edac_dev, char *data)
  339. {
  340. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  341. return sprintf(data, "0x%08x",
  342. in_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJLO));
  343. }
  344. static ssize_t mpc85xx_l2_inject_ctrl_show(struct edac_device_ctl_info
  345. *edac_dev, char *data)
  346. {
  347. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  348. return sprintf(data, "0x%08x",
  349. in_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJCTL));
  350. }
  351. static ssize_t mpc85xx_l2_inject_data_hi_store(struct edac_device_ctl_info
  352. *edac_dev, const char *data,
  353. size_t count)
  354. {
  355. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  356. if (isdigit(*data)) {
  357. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJHI,
  358. simple_strtoul(data, NULL, 0));
  359. return count;
  360. }
  361. return 0;
  362. }
  363. static ssize_t mpc85xx_l2_inject_data_lo_store(struct edac_device_ctl_info
  364. *edac_dev, const char *data,
  365. size_t count)
  366. {
  367. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  368. if (isdigit(*data)) {
  369. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJLO,
  370. simple_strtoul(data, NULL, 0));
  371. return count;
  372. }
  373. return 0;
  374. }
  375. static ssize_t mpc85xx_l2_inject_ctrl_store(struct edac_device_ctl_info
  376. *edac_dev, const char *data,
  377. size_t count)
  378. {
  379. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  380. if (isdigit(*data)) {
  381. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJCTL,
  382. simple_strtoul(data, NULL, 0));
  383. return count;
  384. }
  385. return 0;
  386. }
  387. static struct edac_dev_sysfs_attribute mpc85xx_l2_sysfs_attributes[] = {
  388. {
  389. .attr = {
  390. .name = "inject_data_hi",
  391. .mode = (S_IRUGO | S_IWUSR)
  392. },
  393. .show = mpc85xx_l2_inject_data_hi_show,
  394. .store = mpc85xx_l2_inject_data_hi_store},
  395. {
  396. .attr = {
  397. .name = "inject_data_lo",
  398. .mode = (S_IRUGO | S_IWUSR)
  399. },
  400. .show = mpc85xx_l2_inject_data_lo_show,
  401. .store = mpc85xx_l2_inject_data_lo_store},
  402. {
  403. .attr = {
  404. .name = "inject_ctrl",
  405. .mode = (S_IRUGO | S_IWUSR)
  406. },
  407. .show = mpc85xx_l2_inject_ctrl_show,
  408. .store = mpc85xx_l2_inject_ctrl_store},
  409. /* End of list */
  410. {
  411. .attr = {.name = NULL}
  412. }
  413. };
  414. static void mpc85xx_set_l2_sysfs_attributes(struct edac_device_ctl_info
  415. *edac_dev)
  416. {
  417. edac_dev->sysfs_attributes = mpc85xx_l2_sysfs_attributes;
  418. }
  419. /***************************** L2 ops ***********************************/
  420. static void mpc85xx_l2_check(struct edac_device_ctl_info *edac_dev)
  421. {
  422. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  423. u32 err_detect;
  424. err_detect = in_be32(pdata->l2_vbase + MPC85XX_L2_ERRDET);
  425. if (!(err_detect & L2_EDE_MASK))
  426. return;
  427. printk(KERN_ERR "ECC Error in CPU L2 cache\n");
  428. printk(KERN_ERR "L2 Error Detect Register: 0x%08x\n", err_detect);
  429. printk(KERN_ERR "L2 Error Capture Data High Register: 0x%08x\n",
  430. in_be32(pdata->l2_vbase + MPC85XX_L2_CAPTDATAHI));
  431. printk(KERN_ERR "L2 Error Capture Data Lo Register: 0x%08x\n",
  432. in_be32(pdata->l2_vbase + MPC85XX_L2_CAPTDATALO));
  433. printk(KERN_ERR "L2 Error Syndrome Register: 0x%08x\n",
  434. in_be32(pdata->l2_vbase + MPC85XX_L2_CAPTECC));
  435. printk(KERN_ERR "L2 Error Attributes Capture Register: 0x%08x\n",
  436. in_be32(pdata->l2_vbase + MPC85XX_L2_ERRATTR));
  437. printk(KERN_ERR "L2 Error Address Capture Register: 0x%08x\n",
  438. in_be32(pdata->l2_vbase + MPC85XX_L2_ERRADDR));
  439. /* clear error detect register */
  440. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRDET, err_detect);
  441. if (err_detect & L2_EDE_CE_MASK)
  442. edac_device_handle_ce(edac_dev, 0, 0, edac_dev->ctl_name);
  443. if (err_detect & L2_EDE_UE_MASK)
  444. edac_device_handle_ue(edac_dev, 0, 0, edac_dev->ctl_name);
  445. }
  446. static irqreturn_t mpc85xx_l2_isr(int irq, void *dev_id)
  447. {
  448. struct edac_device_ctl_info *edac_dev = dev_id;
  449. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  450. u32 err_detect;
  451. err_detect = in_be32(pdata->l2_vbase + MPC85XX_L2_ERRDET);
  452. if (!(err_detect & L2_EDE_MASK))
  453. return IRQ_NONE;
  454. mpc85xx_l2_check(edac_dev);
  455. return IRQ_HANDLED;
  456. }
  457. static int mpc85xx_l2_err_probe(struct platform_device *op)
  458. {
  459. struct edac_device_ctl_info *edac_dev;
  460. struct mpc85xx_l2_pdata *pdata;
  461. struct resource r;
  462. int res;
  463. if (!devres_open_group(&op->dev, mpc85xx_l2_err_probe, GFP_KERNEL))
  464. return -ENOMEM;
  465. edac_dev = edac_device_alloc_ctl_info(sizeof(*pdata),
  466. "cpu", 1, "L", 1, 2, NULL, 0,
  467. edac_dev_idx);
  468. if (!edac_dev) {
  469. devres_release_group(&op->dev, mpc85xx_l2_err_probe);
  470. return -ENOMEM;
  471. }
  472. pdata = edac_dev->pvt_info;
  473. pdata->name = "mpc85xx_l2_err";
  474. pdata->irq = NO_IRQ;
  475. edac_dev->dev = &op->dev;
  476. dev_set_drvdata(edac_dev->dev, edac_dev);
  477. edac_dev->ctl_name = pdata->name;
  478. edac_dev->dev_name = pdata->name;
  479. res = of_address_to_resource(op->dev.of_node, 0, &r);
  480. if (res) {
  481. printk(KERN_ERR "%s: Unable to get resource for "
  482. "L2 err regs\n", __func__);
  483. goto err;
  484. }
  485. /* we only need the error registers */
  486. r.start += 0xe00;
  487. if (!devm_request_mem_region(&op->dev, r.start, resource_size(&r),
  488. pdata->name)) {
  489. printk(KERN_ERR "%s: Error while requesting mem region\n",
  490. __func__);
  491. res = -EBUSY;
  492. goto err;
  493. }
  494. pdata->l2_vbase = devm_ioremap(&op->dev, r.start, resource_size(&r));
  495. if (!pdata->l2_vbase) {
  496. printk(KERN_ERR "%s: Unable to setup L2 err regs\n", __func__);
  497. res = -ENOMEM;
  498. goto err;
  499. }
  500. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRDET, ~0);
  501. orig_l2_err_disable = in_be32(pdata->l2_vbase + MPC85XX_L2_ERRDIS);
  502. /* clear the err_dis */
  503. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRDIS, 0);
  504. edac_dev->mod_name = EDAC_MOD_STR;
  505. if (edac_op_state == EDAC_OPSTATE_POLL)
  506. edac_dev->edac_check = mpc85xx_l2_check;
  507. mpc85xx_set_l2_sysfs_attributes(edac_dev);
  508. pdata->edac_idx = edac_dev_idx++;
  509. if (edac_device_add_device(edac_dev) > 0) {
  510. edac_dbg(3, "failed edac_device_add_device()\n");
  511. goto err;
  512. }
  513. if (edac_op_state == EDAC_OPSTATE_INT) {
  514. pdata->irq = irq_of_parse_and_map(op->dev.of_node, 0);
  515. res = devm_request_irq(&op->dev, pdata->irq,
  516. mpc85xx_l2_isr, IRQF_SHARED,
  517. "[EDAC] L2 err", edac_dev);
  518. if (res < 0) {
  519. printk(KERN_ERR
  520. "%s: Unable to request irq %d for "
  521. "MPC85xx L2 err\n", __func__, pdata->irq);
  522. irq_dispose_mapping(pdata->irq);
  523. res = -ENODEV;
  524. goto err2;
  525. }
  526. printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for L2 Err\n",
  527. pdata->irq);
  528. edac_dev->op_state = OP_RUNNING_INTERRUPT;
  529. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINTEN, L2_EIE_MASK);
  530. }
  531. devres_remove_group(&op->dev, mpc85xx_l2_err_probe);
  532. edac_dbg(3, "success\n");
  533. printk(KERN_INFO EDAC_MOD_STR " L2 err registered\n");
  534. return 0;
  535. err2:
  536. edac_device_del_device(&op->dev);
  537. err:
  538. devres_release_group(&op->dev, mpc85xx_l2_err_probe);
  539. edac_device_free_ctl_info(edac_dev);
  540. return res;
  541. }
  542. static int mpc85xx_l2_err_remove(struct platform_device *op)
  543. {
  544. struct edac_device_ctl_info *edac_dev = dev_get_drvdata(&op->dev);
  545. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  546. edac_dbg(0, "\n");
  547. if (edac_op_state == EDAC_OPSTATE_INT) {
  548. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINTEN, 0);
  549. irq_dispose_mapping(pdata->irq);
  550. }
  551. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRDIS, orig_l2_err_disable);
  552. edac_device_del_device(&op->dev);
  553. edac_device_free_ctl_info(edac_dev);
  554. return 0;
  555. }
  556. static const struct of_device_id mpc85xx_l2_err_of_match[] = {
  557. /* deprecate the fsl,85.. forms in the future, 2.6.30? */
  558. { .compatible = "fsl,8540-l2-cache-controller", },
  559. { .compatible = "fsl,8541-l2-cache-controller", },
  560. { .compatible = "fsl,8544-l2-cache-controller", },
  561. { .compatible = "fsl,8548-l2-cache-controller", },
  562. { .compatible = "fsl,8555-l2-cache-controller", },
  563. { .compatible = "fsl,8568-l2-cache-controller", },
  564. { .compatible = "fsl,mpc8536-l2-cache-controller", },
  565. { .compatible = "fsl,mpc8540-l2-cache-controller", },
  566. { .compatible = "fsl,mpc8541-l2-cache-controller", },
  567. { .compatible = "fsl,mpc8544-l2-cache-controller", },
  568. { .compatible = "fsl,mpc8548-l2-cache-controller", },
  569. { .compatible = "fsl,mpc8555-l2-cache-controller", },
  570. { .compatible = "fsl,mpc8560-l2-cache-controller", },
  571. { .compatible = "fsl,mpc8568-l2-cache-controller", },
  572. { .compatible = "fsl,mpc8569-l2-cache-controller", },
  573. { .compatible = "fsl,mpc8572-l2-cache-controller", },
  574. { .compatible = "fsl,p1020-l2-cache-controller", },
  575. { .compatible = "fsl,p1021-l2-cache-controller", },
  576. { .compatible = "fsl,p2020-l2-cache-controller", },
  577. {},
  578. };
  579. MODULE_DEVICE_TABLE(of, mpc85xx_l2_err_of_match);
  580. static struct platform_driver mpc85xx_l2_err_driver = {
  581. .probe = mpc85xx_l2_err_probe,
  582. .remove = mpc85xx_l2_err_remove,
  583. .driver = {
  584. .name = "mpc85xx_l2_err",
  585. .of_match_table = mpc85xx_l2_err_of_match,
  586. },
  587. };
  588. /**************************** MC Err device ***************************/
  589. /*
  590. * Taken from table 8-55 in the MPC8641 User's Manual and/or 9-61 in the
  591. * MPC8572 User's Manual. Each line represents a syndrome bit column as a
  592. * 64-bit value, but split into an upper and lower 32-bit chunk. The labels
  593. * below correspond to Freescale's manuals.
  594. */
  595. static unsigned int ecc_table[16] = {
  596. /* MSB LSB */
  597. /* [0:31] [32:63] */
  598. 0xf00fe11e, 0xc33c0ff7, /* Syndrome bit 7 */
  599. 0x00ff00ff, 0x00fff0ff,
  600. 0x0f0f0f0f, 0x0f0fff00,
  601. 0x11113333, 0x7777000f,
  602. 0x22224444, 0x8888222f,
  603. 0x44448888, 0xffff4441,
  604. 0x8888ffff, 0x11118882,
  605. 0xffff1111, 0x22221114, /* Syndrome bit 0 */
  606. };
  607. /*
  608. * Calculate the correct ECC value for a 64-bit value specified by high:low
  609. */
  610. static u8 calculate_ecc(u32 high, u32 low)
  611. {
  612. u32 mask_low;
  613. u32 mask_high;
  614. int bit_cnt;
  615. u8 ecc = 0;
  616. int i;
  617. int j;
  618. for (i = 0; i < 8; i++) {
  619. mask_high = ecc_table[i * 2];
  620. mask_low = ecc_table[i * 2 + 1];
  621. bit_cnt = 0;
  622. for (j = 0; j < 32; j++) {
  623. if ((mask_high >> j) & 1)
  624. bit_cnt ^= (high >> j) & 1;
  625. if ((mask_low >> j) & 1)
  626. bit_cnt ^= (low >> j) & 1;
  627. }
  628. ecc |= bit_cnt << i;
  629. }
  630. return ecc;
  631. }
  632. /*
  633. * Create the syndrome code which is generated if the data line specified by
  634. * 'bit' failed. Eg generate an 8-bit codes seen in Table 8-55 in the MPC8641
  635. * User's Manual and 9-61 in the MPC8572 User's Manual.
  636. */
  637. static u8 syndrome_from_bit(unsigned int bit) {
  638. int i;
  639. u8 syndrome = 0;
  640. /*
  641. * Cycle through the upper or lower 32-bit portion of each value in
  642. * ecc_table depending on if 'bit' is in the upper or lower half of
  643. * 64-bit data.
  644. */
  645. for (i = bit < 32; i < 16; i += 2)
  646. syndrome |= ((ecc_table[i] >> (bit % 32)) & 1) << (i / 2);
  647. return syndrome;
  648. }
  649. /*
  650. * Decode data and ecc syndrome to determine what went wrong
  651. * Note: This can only decode single-bit errors
  652. */
  653. static void sbe_ecc_decode(u32 cap_high, u32 cap_low, u32 cap_ecc,
  654. int *bad_data_bit, int *bad_ecc_bit)
  655. {
  656. int i;
  657. u8 syndrome;
  658. *bad_data_bit = -1;
  659. *bad_ecc_bit = -1;
  660. /*
  661. * Calculate the ECC of the captured data and XOR it with the captured
  662. * ECC to find an ECC syndrome value we can search for
  663. */
  664. syndrome = calculate_ecc(cap_high, cap_low) ^ cap_ecc;
  665. /* Check if a data line is stuck... */
  666. for (i = 0; i < 64; i++) {
  667. if (syndrome == syndrome_from_bit(i)) {
  668. *bad_data_bit = i;
  669. return;
  670. }
  671. }
  672. /* If data is correct, check ECC bits for errors... */
  673. for (i = 0; i < 8; i++) {
  674. if ((syndrome >> i) & 0x1) {
  675. *bad_ecc_bit = i;
  676. return;
  677. }
  678. }
  679. }
  680. #define make64(high, low) (((u64)(high) << 32) | (low))
  681. static void mpc85xx_mc_check(struct mem_ctl_info *mci)
  682. {
  683. struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
  684. struct csrow_info *csrow;
  685. u32 bus_width;
  686. u32 err_detect;
  687. u32 syndrome;
  688. u64 err_addr;
  689. u32 pfn;
  690. int row_index;
  691. u32 cap_high;
  692. u32 cap_low;
  693. int bad_data_bit;
  694. int bad_ecc_bit;
  695. err_detect = in_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DETECT);
  696. if (!err_detect)
  697. return;
  698. mpc85xx_mc_printk(mci, KERN_ERR, "Err Detect Register: %#8.8x\n",
  699. err_detect);
  700. /* no more processing if not ECC bit errors */
  701. if (!(err_detect & (DDR_EDE_SBE | DDR_EDE_MBE))) {
  702. out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DETECT, err_detect);
  703. return;
  704. }
  705. syndrome = in_be32(pdata->mc_vbase + MPC85XX_MC_CAPTURE_ECC);
  706. /* Mask off appropriate bits of syndrome based on bus width */
  707. bus_width = (in_be32(pdata->mc_vbase + MPC85XX_MC_DDR_SDRAM_CFG) &
  708. DSC_DBW_MASK) ? 32 : 64;
  709. if (bus_width == 64)
  710. syndrome &= 0xff;
  711. else
  712. syndrome &= 0xffff;
  713. err_addr = make64(
  714. in_be32(pdata->mc_vbase + MPC85XX_MC_CAPTURE_EXT_ADDRESS),
  715. in_be32(pdata->mc_vbase + MPC85XX_MC_CAPTURE_ADDRESS));
  716. pfn = err_addr >> PAGE_SHIFT;
  717. for (row_index = 0; row_index < mci->nr_csrows; row_index++) {
  718. csrow = mci->csrows[row_index];
  719. if ((pfn >= csrow->first_page) && (pfn <= csrow->last_page))
  720. break;
  721. }
  722. cap_high = in_be32(pdata->mc_vbase + MPC85XX_MC_CAPTURE_DATA_HI);
  723. cap_low = in_be32(pdata->mc_vbase + MPC85XX_MC_CAPTURE_DATA_LO);
  724. /*
  725. * Analyze single-bit errors on 64-bit wide buses
  726. * TODO: Add support for 32-bit wide buses
  727. */
  728. if ((err_detect & DDR_EDE_SBE) && (bus_width == 64)) {
  729. sbe_ecc_decode(cap_high, cap_low, syndrome,
  730. &bad_data_bit, &bad_ecc_bit);
  731. if (bad_data_bit != -1)
  732. mpc85xx_mc_printk(mci, KERN_ERR,
  733. "Faulty Data bit: %d\n", bad_data_bit);
  734. if (bad_ecc_bit != -1)
  735. mpc85xx_mc_printk(mci, KERN_ERR,
  736. "Faulty ECC bit: %d\n", bad_ecc_bit);
  737. mpc85xx_mc_printk(mci, KERN_ERR,
  738. "Expected Data / ECC:\t%#8.8x_%08x / %#2.2x\n",
  739. cap_high ^ (1 << (bad_data_bit - 32)),
  740. cap_low ^ (1 << bad_data_bit),
  741. syndrome ^ (1 << bad_ecc_bit));
  742. }
  743. mpc85xx_mc_printk(mci, KERN_ERR,
  744. "Captured Data / ECC:\t%#8.8x_%08x / %#2.2x\n",
  745. cap_high, cap_low, syndrome);
  746. mpc85xx_mc_printk(mci, KERN_ERR, "Err addr: %#8.8llx\n", err_addr);
  747. mpc85xx_mc_printk(mci, KERN_ERR, "PFN: %#8.8x\n", pfn);
  748. /* we are out of range */
  749. if (row_index == mci->nr_csrows)
  750. mpc85xx_mc_printk(mci, KERN_ERR, "PFN out of range!\n");
  751. if (err_detect & DDR_EDE_SBE)
  752. edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
  753. pfn, err_addr & ~PAGE_MASK, syndrome,
  754. row_index, 0, -1,
  755. mci->ctl_name, "");
  756. if (err_detect & DDR_EDE_MBE)
  757. edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
  758. pfn, err_addr & ~PAGE_MASK, syndrome,
  759. row_index, 0, -1,
  760. mci->ctl_name, "");
  761. out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DETECT, err_detect);
  762. }
  763. static irqreturn_t mpc85xx_mc_isr(int irq, void *dev_id)
  764. {
  765. struct mem_ctl_info *mci = dev_id;
  766. struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
  767. u32 err_detect;
  768. err_detect = in_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DETECT);
  769. if (!err_detect)
  770. return IRQ_NONE;
  771. mpc85xx_mc_check(mci);
  772. return IRQ_HANDLED;
  773. }
  774. static void mpc85xx_init_csrows(struct mem_ctl_info *mci)
  775. {
  776. struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
  777. struct csrow_info *csrow;
  778. struct dimm_info *dimm;
  779. u32 sdram_ctl;
  780. u32 sdtype;
  781. enum mem_type mtype;
  782. u32 cs_bnds;
  783. int index;
  784. sdram_ctl = in_be32(pdata->mc_vbase + MPC85XX_MC_DDR_SDRAM_CFG);
  785. sdtype = sdram_ctl & DSC_SDTYPE_MASK;
  786. if (sdram_ctl & DSC_RD_EN) {
  787. switch (sdtype) {
  788. case DSC_SDTYPE_DDR:
  789. mtype = MEM_RDDR;
  790. break;
  791. case DSC_SDTYPE_DDR2:
  792. mtype = MEM_RDDR2;
  793. break;
  794. case DSC_SDTYPE_DDR3:
  795. mtype = MEM_RDDR3;
  796. break;
  797. default:
  798. mtype = MEM_UNKNOWN;
  799. break;
  800. }
  801. } else {
  802. switch (sdtype) {
  803. case DSC_SDTYPE_DDR:
  804. mtype = MEM_DDR;
  805. break;
  806. case DSC_SDTYPE_DDR2:
  807. mtype = MEM_DDR2;
  808. break;
  809. case DSC_SDTYPE_DDR3:
  810. mtype = MEM_DDR3;
  811. break;
  812. default:
  813. mtype = MEM_UNKNOWN;
  814. break;
  815. }
  816. }
  817. for (index = 0; index < mci->nr_csrows; index++) {
  818. u32 start;
  819. u32 end;
  820. csrow = mci->csrows[index];
  821. dimm = csrow->channels[0]->dimm;
  822. cs_bnds = in_be32(pdata->mc_vbase + MPC85XX_MC_CS_BNDS_0 +
  823. (index * MPC85XX_MC_CS_BNDS_OFS));
  824. start = (cs_bnds & 0xffff0000) >> 16;
  825. end = (cs_bnds & 0x0000ffff);
  826. if (start == end)
  827. continue; /* not populated */
  828. start <<= (24 - PAGE_SHIFT);
  829. end <<= (24 - PAGE_SHIFT);
  830. end |= (1 << (24 - PAGE_SHIFT)) - 1;
  831. csrow->first_page = start;
  832. csrow->last_page = end;
  833. dimm->nr_pages = end + 1 - start;
  834. dimm->grain = 8;
  835. dimm->mtype = mtype;
  836. dimm->dtype = DEV_UNKNOWN;
  837. if (sdram_ctl & DSC_X32_EN)
  838. dimm->dtype = DEV_X32;
  839. dimm->edac_mode = EDAC_SECDED;
  840. }
  841. }
  842. static int mpc85xx_mc_err_probe(struct platform_device *op)
  843. {
  844. struct mem_ctl_info *mci;
  845. struct edac_mc_layer layers[2];
  846. struct mpc85xx_mc_pdata *pdata;
  847. struct resource r;
  848. u32 sdram_ctl;
  849. int res;
  850. if (!devres_open_group(&op->dev, mpc85xx_mc_err_probe, GFP_KERNEL))
  851. return -ENOMEM;
  852. layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
  853. layers[0].size = 4;
  854. layers[0].is_virt_csrow = true;
  855. layers[1].type = EDAC_MC_LAYER_CHANNEL;
  856. layers[1].size = 1;
  857. layers[1].is_virt_csrow = false;
  858. mci = edac_mc_alloc(edac_mc_idx, ARRAY_SIZE(layers), layers,
  859. sizeof(*pdata));
  860. if (!mci) {
  861. devres_release_group(&op->dev, mpc85xx_mc_err_probe);
  862. return -ENOMEM;
  863. }
  864. pdata = mci->pvt_info;
  865. pdata->name = "mpc85xx_mc_err";
  866. pdata->irq = NO_IRQ;
  867. mci->pdev = &op->dev;
  868. pdata->edac_idx = edac_mc_idx++;
  869. dev_set_drvdata(mci->pdev, mci);
  870. mci->ctl_name = pdata->name;
  871. mci->dev_name = pdata->name;
  872. res = of_address_to_resource(op->dev.of_node, 0, &r);
  873. if (res) {
  874. printk(KERN_ERR "%s: Unable to get resource for MC err regs\n",
  875. __func__);
  876. goto err;
  877. }
  878. if (!devm_request_mem_region(&op->dev, r.start, resource_size(&r),
  879. pdata->name)) {
  880. printk(KERN_ERR "%s: Error while requesting mem region\n",
  881. __func__);
  882. res = -EBUSY;
  883. goto err;
  884. }
  885. pdata->mc_vbase = devm_ioremap(&op->dev, r.start, resource_size(&r));
  886. if (!pdata->mc_vbase) {
  887. printk(KERN_ERR "%s: Unable to setup MC err regs\n", __func__);
  888. res = -ENOMEM;
  889. goto err;
  890. }
  891. sdram_ctl = in_be32(pdata->mc_vbase + MPC85XX_MC_DDR_SDRAM_CFG);
  892. if (!(sdram_ctl & DSC_ECC_EN)) {
  893. /* no ECC */
  894. printk(KERN_WARNING "%s: No ECC DIMMs discovered\n", __func__);
  895. res = -ENODEV;
  896. goto err;
  897. }
  898. edac_dbg(3, "init mci\n");
  899. mci->mtype_cap = MEM_FLAG_RDDR | MEM_FLAG_RDDR2 |
  900. MEM_FLAG_DDR | MEM_FLAG_DDR2;
  901. mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
  902. mci->edac_cap = EDAC_FLAG_SECDED;
  903. mci->mod_name = EDAC_MOD_STR;
  904. mci->mod_ver = MPC85XX_REVISION;
  905. if (edac_op_state == EDAC_OPSTATE_POLL)
  906. mci->edac_check = mpc85xx_mc_check;
  907. mci->ctl_page_to_phys = NULL;
  908. mci->scrub_mode = SCRUB_SW_SRC;
  909. mpc85xx_init_csrows(mci);
  910. /* store the original error disable bits */
  911. orig_ddr_err_disable =
  912. in_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DISABLE);
  913. out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DISABLE, 0);
  914. /* clear all error bits */
  915. out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DETECT, ~0);
  916. if (edac_mc_add_mc_with_groups(mci, mpc85xx_dev_groups)) {
  917. edac_dbg(3, "failed edac_mc_add_mc()\n");
  918. goto err;
  919. }
  920. if (edac_op_state == EDAC_OPSTATE_INT) {
  921. out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_INT_EN,
  922. DDR_EIE_MBEE | DDR_EIE_SBEE);
  923. /* store the original error management threshold */
  924. orig_ddr_err_sbe = in_be32(pdata->mc_vbase +
  925. MPC85XX_MC_ERR_SBE) & 0xff0000;
  926. /* set threshold to 1 error per interrupt */
  927. out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_SBE, 0x10000);
  928. /* register interrupts */
  929. pdata->irq = irq_of_parse_and_map(op->dev.of_node, 0);
  930. res = devm_request_irq(&op->dev, pdata->irq,
  931. mpc85xx_mc_isr,
  932. IRQF_SHARED,
  933. "[EDAC] MC err", mci);
  934. if (res < 0) {
  935. printk(KERN_ERR "%s: Unable to request irq %d for "
  936. "MPC85xx DRAM ERR\n", __func__, pdata->irq);
  937. irq_dispose_mapping(pdata->irq);
  938. res = -ENODEV;
  939. goto err2;
  940. }
  941. printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for MC\n",
  942. pdata->irq);
  943. }
  944. devres_remove_group(&op->dev, mpc85xx_mc_err_probe);
  945. edac_dbg(3, "success\n");
  946. printk(KERN_INFO EDAC_MOD_STR " MC err registered\n");
  947. return 0;
  948. err2:
  949. edac_mc_del_mc(&op->dev);
  950. err:
  951. devres_release_group(&op->dev, mpc85xx_mc_err_probe);
  952. edac_mc_free(mci);
  953. return res;
  954. }
  955. static int mpc85xx_mc_err_remove(struct platform_device *op)
  956. {
  957. struct mem_ctl_info *mci = dev_get_drvdata(&op->dev);
  958. struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
  959. edac_dbg(0, "\n");
  960. if (edac_op_state == EDAC_OPSTATE_INT) {
  961. out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_INT_EN, 0);
  962. irq_dispose_mapping(pdata->irq);
  963. }
  964. out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DISABLE,
  965. orig_ddr_err_disable);
  966. out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_SBE, orig_ddr_err_sbe);
  967. edac_mc_del_mc(&op->dev);
  968. edac_mc_free(mci);
  969. return 0;
  970. }
  971. static const struct of_device_id mpc85xx_mc_err_of_match[] = {
  972. /* deprecate the fsl,85.. forms in the future, 2.6.30? */
  973. { .compatible = "fsl,8540-memory-controller", },
  974. { .compatible = "fsl,8541-memory-controller", },
  975. { .compatible = "fsl,8544-memory-controller", },
  976. { .compatible = "fsl,8548-memory-controller", },
  977. { .compatible = "fsl,8555-memory-controller", },
  978. { .compatible = "fsl,8568-memory-controller", },
  979. { .compatible = "fsl,mpc8536-memory-controller", },
  980. { .compatible = "fsl,mpc8540-memory-controller", },
  981. { .compatible = "fsl,mpc8541-memory-controller", },
  982. { .compatible = "fsl,mpc8544-memory-controller", },
  983. { .compatible = "fsl,mpc8548-memory-controller", },
  984. { .compatible = "fsl,mpc8555-memory-controller", },
  985. { .compatible = "fsl,mpc8560-memory-controller", },
  986. { .compatible = "fsl,mpc8568-memory-controller", },
  987. { .compatible = "fsl,mpc8569-memory-controller", },
  988. { .compatible = "fsl,mpc8572-memory-controller", },
  989. { .compatible = "fsl,mpc8349-memory-controller", },
  990. { .compatible = "fsl,p1020-memory-controller", },
  991. { .compatible = "fsl,p1021-memory-controller", },
  992. { .compatible = "fsl,p2020-memory-controller", },
  993. { .compatible = "fsl,qoriq-memory-controller", },
  994. {},
  995. };
  996. MODULE_DEVICE_TABLE(of, mpc85xx_mc_err_of_match);
  997. static struct platform_driver mpc85xx_mc_err_driver = {
  998. .probe = mpc85xx_mc_err_probe,
  999. .remove = mpc85xx_mc_err_remove,
  1000. .driver = {
  1001. .name = "mpc85xx_mc_err",
  1002. .of_match_table = mpc85xx_mc_err_of_match,
  1003. },
  1004. };
  1005. #ifdef CONFIG_FSL_SOC_BOOKE
  1006. static void __init mpc85xx_mc_clear_rfxe(void *data)
  1007. {
  1008. orig_hid1[smp_processor_id()] = mfspr(SPRN_HID1);
  1009. mtspr(SPRN_HID1, (orig_hid1[smp_processor_id()] & ~HID1_RFXE));
  1010. }
  1011. #endif
  1012. static int __init mpc85xx_mc_init(void)
  1013. {
  1014. int res = 0;
  1015. u32 pvr = 0;
  1016. printk(KERN_INFO "Freescale(R) MPC85xx EDAC driver, "
  1017. "(C) 2006 Montavista Software\n");
  1018. /* make sure error reporting method is sane */
  1019. switch (edac_op_state) {
  1020. case EDAC_OPSTATE_POLL:
  1021. case EDAC_OPSTATE_INT:
  1022. break;
  1023. default:
  1024. edac_op_state = EDAC_OPSTATE_INT;
  1025. break;
  1026. }
  1027. res = platform_driver_register(&mpc85xx_mc_err_driver);
  1028. if (res)
  1029. printk(KERN_WARNING EDAC_MOD_STR "MC fails to register\n");
  1030. res = platform_driver_register(&mpc85xx_l2_err_driver);
  1031. if (res)
  1032. printk(KERN_WARNING EDAC_MOD_STR "L2 fails to register\n");
  1033. #ifdef CONFIG_FSL_SOC_BOOKE
  1034. pvr = mfspr(SPRN_PVR);
  1035. if ((PVR_VER(pvr) == PVR_VER_E500V1) ||
  1036. (PVR_VER(pvr) == PVR_VER_E500V2)) {
  1037. /*
  1038. * need to clear HID1[RFXE] to disable machine check int
  1039. * so we can catch it
  1040. */
  1041. if (edac_op_state == EDAC_OPSTATE_INT)
  1042. on_each_cpu(mpc85xx_mc_clear_rfxe, NULL, 0);
  1043. }
  1044. #endif
  1045. return 0;
  1046. }
  1047. module_init(mpc85xx_mc_init);
  1048. #ifdef CONFIG_FSL_SOC_BOOKE
  1049. static void __exit mpc85xx_mc_restore_hid1(void *data)
  1050. {
  1051. mtspr(SPRN_HID1, orig_hid1[smp_processor_id()]);
  1052. }
  1053. #endif
  1054. static void __exit mpc85xx_mc_exit(void)
  1055. {
  1056. #ifdef CONFIG_FSL_SOC_BOOKE
  1057. u32 pvr = mfspr(SPRN_PVR);
  1058. if ((PVR_VER(pvr) == PVR_VER_E500V1) ||
  1059. (PVR_VER(pvr) == PVR_VER_E500V2)) {
  1060. on_each_cpu(mpc85xx_mc_restore_hid1, NULL, 0);
  1061. }
  1062. #endif
  1063. platform_driver_unregister(&mpc85xx_l2_err_driver);
  1064. platform_driver_unregister(&mpc85xx_mc_err_driver);
  1065. }
  1066. module_exit(mpc85xx_mc_exit);
  1067. MODULE_LICENSE("GPL");
  1068. MODULE_AUTHOR("Montavista Software, Inc.");
  1069. module_param(edac_op_state, int, 0444);
  1070. MODULE_PARM_DESC(edac_op_state,
  1071. "EDAC Error Reporting state: 0=Poll, 2=Interrupt");