ppc4xx_edac.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448
  1. /*
  2. * Copyright (c) 2008 Nuovation System Designs, LLC
  3. * Grant Erickson <gerickson@nuovations.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; version 2 of the
  8. * License.
  9. *
  10. */
  11. #include <linux/edac.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/irq.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mm.h>
  16. #include <linux/module.h>
  17. #include <linux/of_device.h>
  18. #include <linux/of_platform.h>
  19. #include <linux/types.h>
  20. #include <asm/dcr.h>
  21. #include "edac_core.h"
  22. #include "ppc4xx_edac.h"
  23. /*
  24. * This file implements a driver for monitoring and handling events
  25. * associated with the IMB DDR2 ECC controller found in the AMCC/IBM
  26. * 405EX[r], 440SP, 440SPe, 460EX, 460GT and 460SX.
  27. *
  28. * As realized in the 405EX[r], this controller features:
  29. *
  30. * - Support for registered- and non-registered DDR1 and DDR2 memory.
  31. * - 32-bit or 16-bit memory interface with optional ECC.
  32. *
  33. * o ECC support includes:
  34. *
  35. * - 4-bit SEC/DED
  36. * - Aligned-nibble error detect
  37. * - Bypass mode
  38. *
  39. * - Two (2) memory banks/ranks.
  40. * - Up to 1 GiB per bank/rank in 32-bit mode and up to 512 MiB per
  41. * bank/rank in 16-bit mode.
  42. *
  43. * As realized in the 440SP and 440SPe, this controller changes/adds:
  44. *
  45. * - 64-bit or 32-bit memory interface with optional ECC.
  46. *
  47. * o ECC support includes:
  48. *
  49. * - 8-bit SEC/DED
  50. * - Aligned-nibble error detect
  51. * - Bypass mode
  52. *
  53. * - Up to 4 GiB per bank/rank in 64-bit mode and up to 2 GiB
  54. * per bank/rank in 32-bit mode.
  55. *
  56. * As realized in the 460EX and 460GT, this controller changes/adds:
  57. *
  58. * - 64-bit or 32-bit memory interface with optional ECC.
  59. *
  60. * o ECC support includes:
  61. *
  62. * - 8-bit SEC/DED
  63. * - Aligned-nibble error detect
  64. * - Bypass mode
  65. *
  66. * - Four (4) memory banks/ranks.
  67. * - Up to 16 GiB per bank/rank in 64-bit mode and up to 8 GiB
  68. * per bank/rank in 32-bit mode.
  69. *
  70. * At present, this driver has ONLY been tested against the controller
  71. * realization in the 405EX[r] on the AMCC Kilauea and Haleakala
  72. * boards (256 MiB w/o ECC memory soldered onto the board) and a
  73. * proprietary board based on those designs (128 MiB ECC memory, also
  74. * soldered onto the board).
  75. *
  76. * Dynamic feature detection and handling needs to be added for the
  77. * other realizations of this controller listed above.
  78. *
  79. * Eventually, this driver will likely be adapted to the above variant
  80. * realizations of this controller as well as broken apart to handle
  81. * the other known ECC-capable controllers prevalent in other 4xx
  82. * processors:
  83. *
  84. * - IBM SDRAM (405GP, 405CR and 405EP) "ibm,sdram-4xx"
  85. * - IBM DDR1 (440GP, 440GX, 440EP and 440GR) "ibm,sdram-4xx-ddr"
  86. * - Denali DDR1/DDR2 (440EPX and 440GRX) "denali,sdram-4xx-ddr2"
  87. *
  88. * For this controller, unfortunately, correctable errors report
  89. * nothing more than the beat/cycle and byte/lane the correction
  90. * occurred on and the check bit group that covered the error.
  91. *
  92. * In contrast, uncorrectable errors also report the failing address,
  93. * the bus master and the transaction direction (i.e. read or write)
  94. *
  95. * Regardless of whether the error is a CE or a UE, we report the
  96. * following pieces of information in the driver-unique message to the
  97. * EDAC subsystem:
  98. *
  99. * - Device tree path
  100. * - Bank(s)
  101. * - Check bit error group
  102. * - Beat(s)/lane(s)
  103. */
  104. /* Preprocessor Definitions */
  105. #define EDAC_OPSTATE_INT_STR "interrupt"
  106. #define EDAC_OPSTATE_POLL_STR "polled"
  107. #define EDAC_OPSTATE_UNKNOWN_STR "unknown"
  108. #define PPC4XX_EDAC_MODULE_NAME "ppc4xx_edac"
  109. #define PPC4XX_EDAC_MODULE_REVISION "v1.0.0 " __DATE__
  110. #define PPC4XX_EDAC_MESSAGE_SIZE 256
  111. /*
  112. * Kernel logging without an EDAC instance
  113. */
  114. #define ppc4xx_edac_printk(level, fmt, arg...) \
  115. edac_printk(level, "PPC4xx MC", fmt, ##arg)
  116. /*
  117. * Kernel logging with an EDAC instance
  118. */
  119. #define ppc4xx_edac_mc_printk(level, mci, fmt, arg...) \
  120. edac_mc_chipset_printk(mci, level, "PPC4xx", fmt, ##arg)
  121. /*
  122. * Macros to convert bank configuration size enumerations into MiB and
  123. * page values.
  124. */
  125. #define SDRAM_MBCF_SZ_MiB_MIN 4
  126. #define SDRAM_MBCF_SZ_TO_MiB(n) (SDRAM_MBCF_SZ_MiB_MIN \
  127. << (SDRAM_MBCF_SZ_DECODE(n)))
  128. #define SDRAM_MBCF_SZ_TO_PAGES(n) (SDRAM_MBCF_SZ_MiB_MIN \
  129. << (20 - PAGE_SHIFT + \
  130. SDRAM_MBCF_SZ_DECODE(n)))
  131. /*
  132. * The ibm,sdram-4xx-ddr2 Device Control Registers (DCRs) are
  133. * indirectly acccessed and have a base and length defined by the
  134. * device tree. The base can be anything; however, we expect the
  135. * length to be precisely two registers, the first for the address
  136. * window and the second for the data window.
  137. */
  138. #define SDRAM_DCR_RESOURCE_LEN 2
  139. #define SDRAM_DCR_ADDR_OFFSET 0
  140. #define SDRAM_DCR_DATA_OFFSET 1
  141. /*
  142. * Device tree interrupt indices
  143. */
  144. #define INTMAP_ECCDED_INDEX 0 /* Double-bit Error Detect */
  145. #define INTMAP_ECCSEC_INDEX 1 /* Single-bit Error Correct */
  146. /* Type Definitions */
  147. /*
  148. * PPC4xx SDRAM memory controller private instance data
  149. */
  150. struct ppc4xx_edac_pdata {
  151. dcr_host_t dcr_host; /* Indirect DCR address/data window mapping */
  152. struct {
  153. int sec; /* Single-bit correctable error IRQ assigned */
  154. int ded; /* Double-bit detectable error IRQ assigned */
  155. } irqs;
  156. };
  157. /*
  158. * Various status data gathered and manipulated when checking and
  159. * reporting ECC status.
  160. */
  161. struct ppc4xx_ecc_status {
  162. u32 ecces;
  163. u32 besr;
  164. u32 bearh;
  165. u32 bearl;
  166. u32 wmirq;
  167. };
  168. /* Function Prototypes */
  169. static int ppc4xx_edac_probe(struct of_device *device,
  170. const struct of_device_id *device_id);
  171. static int ppc4xx_edac_remove(struct of_device *device);
  172. /* Global Variables */
  173. /*
  174. * Device tree node type and compatible tuples this driver can match
  175. * on.
  176. */
  177. static struct of_device_id ppc4xx_edac_match[] = {
  178. {
  179. .compatible = "ibm,sdram-4xx-ddr2"
  180. },
  181. { }
  182. };
  183. static struct of_platform_driver ppc4xx_edac_driver = {
  184. .match_table = ppc4xx_edac_match,
  185. .probe = ppc4xx_edac_probe,
  186. .remove = ppc4xx_edac_remove,
  187. .driver = {
  188. .owner = THIS_MODULE,
  189. .name = PPC4XX_EDAC_MODULE_NAME
  190. }
  191. };
  192. /*
  193. * TODO: The row and channel parameters likely need to be dynamically
  194. * set based on the aforementioned variant controller realizations.
  195. */
  196. static const unsigned ppc4xx_edac_nr_csrows = 2;
  197. static const unsigned ppc4xx_edac_nr_chans = 1;
  198. /*
  199. * Strings associated with PLB master IDs capable of being posted in
  200. * SDRAM_BESR or SDRAM_WMIRQ on uncorrectable ECC errors.
  201. */
  202. static const char * const ppc4xx_plb_masters[9] = {
  203. [SDRAM_PLB_M0ID_ICU] = "ICU",
  204. [SDRAM_PLB_M0ID_PCIE0] = "PCI-E 0",
  205. [SDRAM_PLB_M0ID_PCIE1] = "PCI-E 1",
  206. [SDRAM_PLB_M0ID_DMA] = "DMA",
  207. [SDRAM_PLB_M0ID_DCU] = "DCU",
  208. [SDRAM_PLB_M0ID_OPB] = "OPB",
  209. [SDRAM_PLB_M0ID_MAL] = "MAL",
  210. [SDRAM_PLB_M0ID_SEC] = "SEC",
  211. [SDRAM_PLB_M0ID_AHB] = "AHB"
  212. };
  213. /**
  214. * mfsdram - read and return controller register data
  215. * @dcr_host: A pointer to the DCR mapping.
  216. * @idcr_n: The indirect DCR register to read.
  217. *
  218. * This routine reads and returns the data associated with the
  219. * controller's specified indirect DCR register.
  220. *
  221. * Returns the read data.
  222. */
  223. static inline u32
  224. mfsdram(const dcr_host_t *dcr_host, unsigned int idcr_n)
  225. {
  226. return __mfdcri(dcr_host->base + SDRAM_DCR_ADDR_OFFSET,
  227. dcr_host->base + SDRAM_DCR_DATA_OFFSET,
  228. idcr_n);
  229. }
  230. /**
  231. * mtsdram - write controller register data
  232. * @dcr_host: A pointer to the DCR mapping.
  233. * @idcr_n: The indirect DCR register to write.
  234. * @value: The data to write.
  235. *
  236. * This routine writes the provided data to the controller's specified
  237. * indirect DCR register.
  238. */
  239. static inline void
  240. mtsdram(const dcr_host_t *dcr_host, unsigned int idcr_n, u32 value)
  241. {
  242. return __mtdcri(dcr_host->base + SDRAM_DCR_ADDR_OFFSET,
  243. dcr_host->base + SDRAM_DCR_DATA_OFFSET,
  244. idcr_n,
  245. value);
  246. }
  247. /**
  248. * ppc4xx_edac_check_bank_error - check a bank for an ECC bank error
  249. * @status: A pointer to the ECC status structure to check for an
  250. * ECC bank error.
  251. * @bank: The bank to check for an ECC error.
  252. *
  253. * This routine determines whether the specified bank has an ECC
  254. * error.
  255. *
  256. * Returns true if the specified bank has an ECC error; otherwise,
  257. * false.
  258. */
  259. static bool
  260. ppc4xx_edac_check_bank_error(const struct ppc4xx_ecc_status *status,
  261. unsigned int bank)
  262. {
  263. switch (bank) {
  264. case 0:
  265. return status->ecces & SDRAM_ECCES_BK0ER;
  266. case 1:
  267. return status->ecces & SDRAM_ECCES_BK1ER;
  268. default:
  269. return false;
  270. }
  271. }
  272. /**
  273. * ppc4xx_edac_generate_bank_message - generate interpretted bank status message
  274. * @mci: A pointer to the EDAC memory controller instance associated
  275. * with the bank message being generated.
  276. * @status: A pointer to the ECC status structure to generate the
  277. * message from.
  278. * @buffer: A pointer to the buffer in which to generate the
  279. * message.
  280. * @size: The size, in bytes, of space available in buffer.
  281. *
  282. * This routine generates to the provided buffer the portion of the
  283. * driver-unique report message associated with the ECCESS[BKNER]
  284. * field of the specified ECC status.
  285. *
  286. * Returns the number of characters generated on success; otherwise, <
  287. * 0 on error.
  288. */
  289. static int
  290. ppc4xx_edac_generate_bank_message(const struct mem_ctl_info *mci,
  291. const struct ppc4xx_ecc_status *status,
  292. char *buffer,
  293. size_t size)
  294. {
  295. int n, total = 0;
  296. unsigned int row, rows;
  297. n = snprintf(buffer, size, "%s: Banks: ", mci->dev_name);
  298. if (n < 0 || n >= size)
  299. goto fail;
  300. buffer += n;
  301. size -= n;
  302. total += n;
  303. for (rows = 0, row = 0; row < mci->nr_csrows; row++) {
  304. if (ppc4xx_edac_check_bank_error(status, row)) {
  305. n = snprintf(buffer, size, "%s%u",
  306. (rows++ ? ", " : ""), row);
  307. if (n < 0 || n >= size)
  308. goto fail;
  309. buffer += n;
  310. size -= n;
  311. total += n;
  312. }
  313. }
  314. n = snprintf(buffer, size, "%s; ", rows ? "" : "None");
  315. if (n < 0 || n >= size)
  316. goto fail;
  317. buffer += n;
  318. size -= n;
  319. total += n;
  320. fail:
  321. return total;
  322. }
  323. /**
  324. * ppc4xx_edac_generate_checkbit_message - generate interpretted checkbit message
  325. * @mci: A pointer to the EDAC memory controller instance associated
  326. * with the checkbit message being generated.
  327. * @status: A pointer to the ECC status structure to generate the
  328. * message from.
  329. * @buffer: A pointer to the buffer in which to generate the
  330. * message.
  331. * @size: The size, in bytes, of space available in buffer.
  332. *
  333. * This routine generates to the provided buffer the portion of the
  334. * driver-unique report message associated with the ECCESS[CKBER]
  335. * field of the specified ECC status.
  336. *
  337. * Returns the number of characters generated on success; otherwise, <
  338. * 0 on error.
  339. */
  340. static int
  341. ppc4xx_edac_generate_checkbit_message(const struct mem_ctl_info *mci,
  342. const struct ppc4xx_ecc_status *status,
  343. char *buffer,
  344. size_t size)
  345. {
  346. const struct ppc4xx_edac_pdata *pdata = mci->pvt_info;
  347. const char *ckber = NULL;
  348. switch (status->ecces & SDRAM_ECCES_CKBER_MASK) {
  349. case SDRAM_ECCES_CKBER_NONE:
  350. ckber = "None";
  351. break;
  352. case SDRAM_ECCES_CKBER_32_ECC_0_3:
  353. ckber = "ECC0:3";
  354. break;
  355. case SDRAM_ECCES_CKBER_32_ECC_4_8:
  356. switch (mfsdram(&pdata->dcr_host, SDRAM_MCOPT1) &
  357. SDRAM_MCOPT1_WDTH_MASK) {
  358. case SDRAM_MCOPT1_WDTH_16:
  359. ckber = "ECC0:3";
  360. break;
  361. case SDRAM_MCOPT1_WDTH_32:
  362. ckber = "ECC4:8";
  363. break;
  364. default:
  365. ckber = "Unknown";
  366. break;
  367. }
  368. break;
  369. case SDRAM_ECCES_CKBER_32_ECC_0_8:
  370. ckber = "ECC0:8";
  371. break;
  372. default:
  373. ckber = "Unknown";
  374. break;
  375. }
  376. return snprintf(buffer, size, "Checkbit Error: %s", ckber);
  377. }
  378. /**
  379. * ppc4xx_edac_generate_lane_message - generate interpretted byte lane message
  380. * @mci: A pointer to the EDAC memory controller instance associated
  381. * with the byte lane message being generated.
  382. * @status: A pointer to the ECC status structure to generate the
  383. * message from.
  384. * @buffer: A pointer to the buffer in which to generate the
  385. * message.
  386. * @size: The size, in bytes, of space available in buffer.
  387. *
  388. * This routine generates to the provided buffer the portion of the
  389. * driver-unique report message associated with the ECCESS[BNCE]
  390. * field of the specified ECC status.
  391. *
  392. * Returns the number of characters generated on success; otherwise, <
  393. * 0 on error.
  394. */
  395. static int
  396. ppc4xx_edac_generate_lane_message(const struct mem_ctl_info *mci,
  397. const struct ppc4xx_ecc_status *status,
  398. char *buffer,
  399. size_t size)
  400. {
  401. int n, total = 0;
  402. unsigned int lane, lanes;
  403. const unsigned int first_lane = 0;
  404. const unsigned int lane_count = 16;
  405. n = snprintf(buffer, size, "; Byte Lane Errors: ");
  406. if (n < 0 || n >= size)
  407. goto fail;
  408. buffer += n;
  409. size -= n;
  410. total += n;
  411. for (lanes = 0, lane = first_lane; lane < lane_count; lane++) {
  412. if ((status->ecces & SDRAM_ECCES_BNCE_ENCODE(lane)) != 0) {
  413. n = snprintf(buffer, size,
  414. "%s%u",
  415. (lanes++ ? ", " : ""), lane);
  416. if (n < 0 || n >= size)
  417. goto fail;
  418. buffer += n;
  419. size -= n;
  420. total += n;
  421. }
  422. }
  423. n = snprintf(buffer, size, "%s; ", lanes ? "" : "None");
  424. if (n < 0 || n >= size)
  425. goto fail;
  426. buffer += n;
  427. size -= n;
  428. total += n;
  429. fail:
  430. return total;
  431. }
  432. /**
  433. * ppc4xx_edac_generate_ecc_message - generate interpretted ECC status message
  434. * @mci: A pointer to the EDAC memory controller instance associated
  435. * with the ECCES message being generated.
  436. * @status: A pointer to the ECC status structure to generate the
  437. * message from.
  438. * @buffer: A pointer to the buffer in which to generate the
  439. * message.
  440. * @size: The size, in bytes, of space available in buffer.
  441. *
  442. * This routine generates to the provided buffer the portion of the
  443. * driver-unique report message associated with the ECCESS register of
  444. * the specified ECC status.
  445. *
  446. * Returns the number of characters generated on success; otherwise, <
  447. * 0 on error.
  448. */
  449. static int
  450. ppc4xx_edac_generate_ecc_message(const struct mem_ctl_info *mci,
  451. const struct ppc4xx_ecc_status *status,
  452. char *buffer,
  453. size_t size)
  454. {
  455. int n, total = 0;
  456. n = ppc4xx_edac_generate_bank_message(mci, status, buffer, size);
  457. if (n < 0 || n >= size)
  458. goto fail;
  459. buffer += n;
  460. size -= n;
  461. total += n;
  462. n = ppc4xx_edac_generate_checkbit_message(mci, status, buffer, size);
  463. if (n < 0 || n >= size)
  464. goto fail;
  465. buffer += n;
  466. size -= n;
  467. total += n;
  468. n = ppc4xx_edac_generate_lane_message(mci, status, buffer, size);
  469. if (n < 0 || n >= size)
  470. goto fail;
  471. buffer += n;
  472. size -= n;
  473. total += n;
  474. fail:
  475. return total;
  476. }
  477. /**
  478. * ppc4xx_edac_generate_plb_message - generate interpretted PLB status message
  479. * @mci: A pointer to the EDAC memory controller instance associated
  480. * with the PLB message being generated.
  481. * @status: A pointer to the ECC status structure to generate the
  482. * message from.
  483. * @buffer: A pointer to the buffer in which to generate the
  484. * message.
  485. * @size: The size, in bytes, of space available in buffer.
  486. *
  487. * This routine generates to the provided buffer the portion of the
  488. * driver-unique report message associated with the PLB-related BESR
  489. * and/or WMIRQ registers of the specified ECC status.
  490. *
  491. * Returns the number of characters generated on success; otherwise, <
  492. * 0 on error.
  493. */
  494. static int
  495. ppc4xx_edac_generate_plb_message(const struct mem_ctl_info *mci,
  496. const struct ppc4xx_ecc_status *status,
  497. char *buffer,
  498. size_t size)
  499. {
  500. unsigned int master;
  501. bool read;
  502. if ((status->besr & SDRAM_BESR_MASK) == 0)
  503. return 0;
  504. if ((status->besr & SDRAM_BESR_M0ET_MASK) == SDRAM_BESR_M0ET_NONE)
  505. return 0;
  506. read = ((status->besr & SDRAM_BESR_M0RW_MASK) == SDRAM_BESR_M0RW_READ);
  507. master = SDRAM_BESR_M0ID_DECODE(status->besr);
  508. return snprintf(buffer, size,
  509. "%s error w/ PLB master %u \"%s\"; ",
  510. (read ? "Read" : "Write"),
  511. master,
  512. (((master >= SDRAM_PLB_M0ID_FIRST) &&
  513. (master <= SDRAM_PLB_M0ID_LAST)) ?
  514. ppc4xx_plb_masters[master] : "UNKNOWN"));
  515. }
  516. /**
  517. * ppc4xx_edac_generate_message - generate interpretted status message
  518. * @mci: A pointer to the EDAC memory controller instance associated
  519. * with the driver-unique message being generated.
  520. * @status: A pointer to the ECC status structure to generate the
  521. * message from.
  522. * @buffer: A pointer to the buffer in which to generate the
  523. * message.
  524. * @size: The size, in bytes, of space available in buffer.
  525. *
  526. * This routine generates to the provided buffer the driver-unique
  527. * EDAC report message from the specified ECC status.
  528. */
  529. static void
  530. ppc4xx_edac_generate_message(const struct mem_ctl_info *mci,
  531. const struct ppc4xx_ecc_status *status,
  532. char *buffer,
  533. size_t size)
  534. {
  535. int n;
  536. if (buffer == NULL || size == 0)
  537. return;
  538. n = ppc4xx_edac_generate_ecc_message(mci, status, buffer, size);
  539. if (n < 0 || n >= size)
  540. return;
  541. buffer += n;
  542. size -= n;
  543. ppc4xx_edac_generate_plb_message(mci, status, buffer, size);
  544. }
  545. #ifdef DEBUG
  546. /**
  547. * ppc4xx_ecc_dump_status - dump controller ECC status registers
  548. * @mci: A pointer to the EDAC memory controller instance
  549. * associated with the status being dumped.
  550. * @status: A pointer to the ECC status structure to generate the
  551. * dump from.
  552. *
  553. * This routine dumps to the kernel log buffer the raw and
  554. * interpretted specified ECC status.
  555. */
  556. static void
  557. ppc4xx_ecc_dump_status(const struct mem_ctl_info *mci,
  558. const struct ppc4xx_ecc_status *status)
  559. {
  560. char message[PPC4XX_EDAC_MESSAGE_SIZE];
  561. ppc4xx_edac_generate_message(mci, status, message, sizeof(message));
  562. ppc4xx_edac_mc_printk(KERN_INFO, mci,
  563. "\n"
  564. "\tECCES: 0x%08x\n"
  565. "\tWMIRQ: 0x%08x\n"
  566. "\tBESR: 0x%08x\n"
  567. "\tBEAR: 0x%08x%08x\n"
  568. "\t%s\n",
  569. status->ecces,
  570. status->wmirq,
  571. status->besr,
  572. status->bearh,
  573. status->bearl,
  574. message);
  575. }
  576. #endif /* DEBUG */
  577. /**
  578. * ppc4xx_ecc_get_status - get controller ECC status
  579. * @mci: A pointer to the EDAC memory controller instance
  580. * associated with the status being retrieved.
  581. * @status: A pointer to the ECC status structure to populate the
  582. * ECC status with.
  583. *
  584. * This routine reads and masks, as appropriate, all the relevant
  585. * status registers that deal with ibm,sdram-4xx-ddr2 ECC errors.
  586. * While we read all of them, for correctable errors, we only expect
  587. * to deal with ECCES. For uncorrectable errors, we expect to deal
  588. * with all of them.
  589. */
  590. static void
  591. ppc4xx_ecc_get_status(const struct mem_ctl_info *mci,
  592. struct ppc4xx_ecc_status *status)
  593. {
  594. const struct ppc4xx_edac_pdata *pdata = mci->pvt_info;
  595. const dcr_host_t *dcr_host = &pdata->dcr_host;
  596. status->ecces = mfsdram(dcr_host, SDRAM_ECCES) & SDRAM_ECCES_MASK;
  597. status->wmirq = mfsdram(dcr_host, SDRAM_WMIRQ) & SDRAM_WMIRQ_MASK;
  598. status->besr = mfsdram(dcr_host, SDRAM_BESR) & SDRAM_BESR_MASK;
  599. status->bearl = mfsdram(dcr_host, SDRAM_BEARL);
  600. status->bearh = mfsdram(dcr_host, SDRAM_BEARH);
  601. }
  602. /**
  603. * ppc4xx_ecc_clear_status - clear controller ECC status
  604. * @mci: A pointer to the EDAC memory controller instance
  605. * associated with the status being cleared.
  606. * @status: A pointer to the ECC status structure containing the
  607. * values to write to clear the ECC status.
  608. *
  609. * This routine clears--by writing the masked (as appropriate) status
  610. * values back to--the status registers that deal with
  611. * ibm,sdram-4xx-ddr2 ECC errors.
  612. */
  613. static void
  614. ppc4xx_ecc_clear_status(const struct mem_ctl_info *mci,
  615. const struct ppc4xx_ecc_status *status)
  616. {
  617. const struct ppc4xx_edac_pdata *pdata = mci->pvt_info;
  618. const dcr_host_t *dcr_host = &pdata->dcr_host;
  619. mtsdram(dcr_host, SDRAM_ECCES, status->ecces & SDRAM_ECCES_MASK);
  620. mtsdram(dcr_host, SDRAM_WMIRQ, status->wmirq & SDRAM_WMIRQ_MASK);
  621. mtsdram(dcr_host, SDRAM_BESR, status->besr & SDRAM_BESR_MASK);
  622. mtsdram(dcr_host, SDRAM_BEARL, 0);
  623. mtsdram(dcr_host, SDRAM_BEARH, 0);
  624. }
  625. /**
  626. * ppc4xx_edac_handle_ce - handle controller correctable ECC error (CE)
  627. * @mci: A pointer to the EDAC memory controller instance
  628. * associated with the correctable error being handled and reported.
  629. * @status: A pointer to the ECC status structure associated with
  630. * the correctable error being handled and reported.
  631. *
  632. * This routine handles an ibm,sdram-4xx-ddr2 controller ECC
  633. * correctable error. Per the aforementioned discussion, there's not
  634. * enough status available to use the full EDAC correctable error
  635. * interface, so we just pass driver-unique message to the "no info"
  636. * interface.
  637. */
  638. static void
  639. ppc4xx_edac_handle_ce(struct mem_ctl_info *mci,
  640. const struct ppc4xx_ecc_status *status)
  641. {
  642. int row;
  643. char message[PPC4XX_EDAC_MESSAGE_SIZE];
  644. ppc4xx_edac_generate_message(mci, status, message, sizeof(message));
  645. for (row = 0; row < mci->nr_csrows; row++)
  646. if (ppc4xx_edac_check_bank_error(status, row))
  647. edac_mc_handle_ce_no_info(mci, message);
  648. }
  649. /**
  650. * ppc4xx_edac_handle_ue - handle controller uncorrectable ECC error (UE)
  651. * @mci: A pointer to the EDAC memory controller instance
  652. * associated with the uncorrectable error being handled and
  653. * reported.
  654. * @status: A pointer to the ECC status structure associated with
  655. * the uncorrectable error being handled and reported.
  656. *
  657. * This routine handles an ibm,sdram-4xx-ddr2 controller ECC
  658. * uncorrectable error.
  659. */
  660. static void
  661. ppc4xx_edac_handle_ue(struct mem_ctl_info *mci,
  662. const struct ppc4xx_ecc_status *status)
  663. {
  664. const u64 bear = ((u64)status->bearh << 32 | status->bearl);
  665. const unsigned long page = bear >> PAGE_SHIFT;
  666. const unsigned long offset = bear & ~PAGE_MASK;
  667. int row;
  668. char message[PPC4XX_EDAC_MESSAGE_SIZE];
  669. ppc4xx_edac_generate_message(mci, status, message, sizeof(message));
  670. for (row = 0; row < mci->nr_csrows; row++)
  671. if (ppc4xx_edac_check_bank_error(status, row))
  672. edac_mc_handle_ue(mci, page, offset, row, message);
  673. }
  674. /**
  675. * ppc4xx_edac_check - check controller for ECC errors
  676. * @mci: A pointer to the EDAC memory controller instance
  677. * associated with the ibm,sdram-4xx-ddr2 controller being
  678. * checked.
  679. *
  680. * This routine is used to check and post ECC errors and is called by
  681. * both the EDAC polling thread and this driver's CE and UE interrupt
  682. * handler.
  683. */
  684. static void
  685. ppc4xx_edac_check(struct mem_ctl_info *mci)
  686. {
  687. #ifdef DEBUG
  688. static unsigned int count;
  689. #endif
  690. struct ppc4xx_ecc_status status;
  691. ppc4xx_ecc_get_status(mci, &status);
  692. #ifdef DEBUG
  693. if (count++ % 30 == 0)
  694. ppc4xx_ecc_dump_status(mci, &status);
  695. #endif
  696. if (status.ecces & SDRAM_ECCES_UE)
  697. ppc4xx_edac_handle_ue(mci, &status);
  698. if (status.ecces & SDRAM_ECCES_CE)
  699. ppc4xx_edac_handle_ce(mci, &status);
  700. ppc4xx_ecc_clear_status(mci, &status);
  701. }
  702. /**
  703. * ppc4xx_edac_isr - SEC (CE) and DED (UE) interrupt service routine
  704. * @irq: The virtual interrupt number being serviced.
  705. * @dev_id: A pointer to the EDAC memory controller instance
  706. * associated with the interrupt being handled.
  707. *
  708. * This routine implements the interrupt handler for both correctable
  709. * (CE) and uncorrectable (UE) ECC errors for the ibm,sdram-4xx-ddr2
  710. * controller. It simply calls through to the same routine used during
  711. * polling to check, report and clear the ECC status.
  712. *
  713. * Unconditionally returns IRQ_HANDLED.
  714. */
  715. static irqreturn_t
  716. ppc4xx_edac_isr(int irq, void *dev_id)
  717. {
  718. struct mem_ctl_info *mci = dev_id;
  719. ppc4xx_edac_check(mci);
  720. return IRQ_HANDLED;
  721. }
  722. /**
  723. * ppc4xx_edac_get_dtype - return the controller memory width
  724. * @mcopt1: The 32-bit Memory Controller Option 1 register value
  725. * currently set for the controller, from which the width
  726. * is derived.
  727. *
  728. * This routine returns the EDAC device type width appropriate for the
  729. * current controller configuration.
  730. *
  731. * TODO: This needs to be conditioned dynamically through feature
  732. * flags or some such when other controller variants are supported as
  733. * the 405EX[r] is 16-/32-bit and the others are 32-/64-bit with the
  734. * 16- and 64-bit field definition/value/enumeration (b1) overloaded
  735. * among them.
  736. *
  737. * Returns a device type width enumeration.
  738. */
  739. static enum dev_type __devinit
  740. ppc4xx_edac_get_dtype(u32 mcopt1)
  741. {
  742. switch (mcopt1 & SDRAM_MCOPT1_WDTH_MASK) {
  743. case SDRAM_MCOPT1_WDTH_16:
  744. return DEV_X2;
  745. case SDRAM_MCOPT1_WDTH_32:
  746. return DEV_X4;
  747. default:
  748. return DEV_UNKNOWN;
  749. }
  750. }
  751. /**
  752. * ppc4xx_edac_get_mtype - return controller memory type
  753. * @mcopt1: The 32-bit Memory Controller Option 1 register value
  754. * currently set for the controller, from which the memory type
  755. * is derived.
  756. *
  757. * This routine returns the EDAC memory type appropriate for the
  758. * current controller configuration.
  759. *
  760. * Returns a memory type enumeration.
  761. */
  762. static enum mem_type __devinit
  763. ppc4xx_edac_get_mtype(u32 mcopt1)
  764. {
  765. bool rden = ((mcopt1 & SDRAM_MCOPT1_RDEN_MASK) == SDRAM_MCOPT1_RDEN);
  766. switch (mcopt1 & SDRAM_MCOPT1_DDR_TYPE_MASK) {
  767. case SDRAM_MCOPT1_DDR2_TYPE:
  768. return rden ? MEM_RDDR2 : MEM_DDR2;
  769. case SDRAM_MCOPT1_DDR1_TYPE:
  770. return rden ? MEM_RDDR : MEM_DDR;
  771. default:
  772. return MEM_UNKNOWN;
  773. }
  774. }
  775. /**
  776. * ppc4xx_edac_init_csrows - intialize driver instance rows
  777. * @mci: A pointer to the EDAC memory controller instance
  778. * associated with the ibm,sdram-4xx-ddr2 controller for which
  779. * the csrows (i.e. banks/ranks) are being initialized.
  780. * @mcopt1: The 32-bit Memory Controller Option 1 register value
  781. * currently set for the controller, from which bank width
  782. * and memory typ information is derived.
  783. *
  784. * This routine intializes the virtual "chip select rows" associated
  785. * with the EDAC memory controller instance. An ibm,sdram-4xx-ddr2
  786. * controller bank/rank is mapped to a row.
  787. *
  788. * Returns 0 if OK; otherwise, -EINVAL if the memory bank size
  789. * configuration cannot be determined.
  790. */
  791. static int __devinit
  792. ppc4xx_edac_init_csrows(struct mem_ctl_info *mci, u32 mcopt1)
  793. {
  794. const struct ppc4xx_edac_pdata *pdata = mci->pvt_info;
  795. int status = 0;
  796. enum mem_type mtype;
  797. enum dev_type dtype;
  798. enum edac_type edac_mode;
  799. int row;
  800. u32 mbxcf, size;
  801. static u32 ppc4xx_last_page;
  802. /* Establish the memory type and width */
  803. mtype = ppc4xx_edac_get_mtype(mcopt1);
  804. dtype = ppc4xx_edac_get_dtype(mcopt1);
  805. /* Establish EDAC mode */
  806. if (mci->edac_cap & EDAC_FLAG_SECDED)
  807. edac_mode = EDAC_SECDED;
  808. else if (mci->edac_cap & EDAC_FLAG_EC)
  809. edac_mode = EDAC_EC;
  810. else
  811. edac_mode = EDAC_NONE;
  812. /*
  813. * Initialize each chip select row structure which correspond
  814. * 1:1 with a controller bank/rank.
  815. */
  816. for (row = 0; row < mci->nr_csrows; row++) {
  817. struct csrow_info *csi = &mci->csrows[row];
  818. /*
  819. * Get the configuration settings for this
  820. * row/bank/rank and skip disabled banks.
  821. */
  822. mbxcf = mfsdram(&pdata->dcr_host, SDRAM_MBXCF(row));
  823. if ((mbxcf & SDRAM_MBCF_BE_MASK) != SDRAM_MBCF_BE_ENABLE)
  824. continue;
  825. /* Map the bank configuration size setting to pages. */
  826. size = mbxcf & SDRAM_MBCF_SZ_MASK;
  827. switch (size) {
  828. case SDRAM_MBCF_SZ_4MB:
  829. case SDRAM_MBCF_SZ_8MB:
  830. case SDRAM_MBCF_SZ_16MB:
  831. case SDRAM_MBCF_SZ_32MB:
  832. case SDRAM_MBCF_SZ_64MB:
  833. case SDRAM_MBCF_SZ_128MB:
  834. case SDRAM_MBCF_SZ_256MB:
  835. case SDRAM_MBCF_SZ_512MB:
  836. case SDRAM_MBCF_SZ_1GB:
  837. case SDRAM_MBCF_SZ_2GB:
  838. case SDRAM_MBCF_SZ_4GB:
  839. case SDRAM_MBCF_SZ_8GB:
  840. csi->nr_pages = SDRAM_MBCF_SZ_TO_PAGES(size);
  841. break;
  842. default:
  843. ppc4xx_edac_mc_printk(KERN_ERR, mci,
  844. "Unrecognized memory bank %d "
  845. "size 0x%08x\n",
  846. row, SDRAM_MBCF_SZ_DECODE(size));
  847. status = -EINVAL;
  848. goto done;
  849. }
  850. csi->first_page = ppc4xx_last_page;
  851. csi->last_page = csi->first_page + csi->nr_pages - 1;
  852. csi->page_mask = 0;
  853. /*
  854. * It's unclear exactly what grain should be set to
  855. * here. The SDRAM_ECCES register allows resolution of
  856. * an error down to a nibble which would potentially
  857. * argue for a grain of '1' byte, even though we only
  858. * know the associated address for uncorrectable
  859. * errors. This value is not used at present for
  860. * anything other than error reporting so getting it
  861. * wrong should be of little consequence. Other
  862. * possible values would be the PLB width (16), the
  863. * page size (PAGE_SIZE) or the memory width (2 or 4).
  864. */
  865. csi->grain = 1;
  866. csi->mtype = mtype;
  867. csi->dtype = dtype;
  868. csi->edac_mode = edac_mode;
  869. ppc4xx_last_page += csi->nr_pages;
  870. }
  871. done:
  872. return status;
  873. }
  874. /**
  875. * ppc4xx_edac_mc_init - intialize driver instance
  876. * @mci: A pointer to the EDAC memory controller instance being
  877. * initialized.
  878. * @op: A pointer to the OpenFirmware device tree node associated
  879. * with the controller this EDAC instance is bound to.
  880. * @match: A pointer to the OpenFirmware device tree match
  881. * information associated with the controller this EDAC instance
  882. * is bound to.
  883. * @dcr_host: A pointer to the DCR data containing the DCR mapping
  884. * for this controller instance.
  885. * @mcopt1: The 32-bit Memory Controller Option 1 register value
  886. * currently set for the controller, from which ECC capabilities
  887. * and scrub mode are derived.
  888. *
  889. * This routine performs initialization of the EDAC memory controller
  890. * instance and related driver-private data associated with the
  891. * ibm,sdram-4xx-ddr2 memory controller the instance is bound to.
  892. *
  893. * Returns 0 if OK; otherwise, < 0 on error.
  894. */
  895. static int __devinit
  896. ppc4xx_edac_mc_init(struct mem_ctl_info *mci,
  897. struct of_device *op,
  898. const struct of_device_id *match,
  899. const dcr_host_t *dcr_host,
  900. u32 mcopt1)
  901. {
  902. int status = 0;
  903. const u32 memcheck = (mcopt1 & SDRAM_MCOPT1_MCHK_MASK);
  904. struct ppc4xx_edac_pdata *pdata = NULL;
  905. const struct device_node *np = op->node;
  906. if (match == NULL)
  907. return -EINVAL;
  908. /* Initial driver pointers and private data */
  909. mci->dev = &op->dev;
  910. dev_set_drvdata(mci->dev, mci);
  911. pdata = mci->pvt_info;
  912. pdata->dcr_host = *dcr_host;
  913. pdata->irqs.sec = NO_IRQ;
  914. pdata->irqs.ded = NO_IRQ;
  915. /* Initialize controller capabilities and configuration */
  916. mci->mtype_cap = (MEM_FLAG_DDR | MEM_FLAG_RDDR |
  917. MEM_FLAG_DDR2 | MEM_FLAG_RDDR2);
  918. mci->edac_ctl_cap = (EDAC_FLAG_NONE |
  919. EDAC_FLAG_EC |
  920. EDAC_FLAG_SECDED);
  921. mci->scrub_cap = SCRUB_NONE;
  922. mci->scrub_mode = SCRUB_NONE;
  923. /*
  924. * Update the actual capabilites based on the MCOPT1[MCHK]
  925. * settings. Scrubbing is only useful if reporting is enabled.
  926. */
  927. switch (memcheck) {
  928. case SDRAM_MCOPT1_MCHK_CHK:
  929. mci->edac_cap = EDAC_FLAG_EC;
  930. break;
  931. case SDRAM_MCOPT1_MCHK_CHK_REP:
  932. mci->edac_cap = (EDAC_FLAG_EC | EDAC_FLAG_SECDED);
  933. mci->scrub_mode = SCRUB_SW_SRC;
  934. break;
  935. default:
  936. mci->edac_cap = EDAC_FLAG_NONE;
  937. break;
  938. }
  939. /* Initialize strings */
  940. mci->mod_name = PPC4XX_EDAC_MODULE_NAME;
  941. mci->mod_ver = PPC4XX_EDAC_MODULE_REVISION;
  942. mci->ctl_name = match->compatible,
  943. mci->dev_name = np->full_name;
  944. /* Initialize callbacks */
  945. mci->edac_check = ppc4xx_edac_check;
  946. mci->ctl_page_to_phys = NULL;
  947. /* Initialize chip select rows */
  948. status = ppc4xx_edac_init_csrows(mci, mcopt1);
  949. if (status)
  950. ppc4xx_edac_mc_printk(KERN_ERR, mci,
  951. "Failed to initialize rows!\n");
  952. return status;
  953. }
  954. /**
  955. * ppc4xx_edac_register_irq - setup and register controller interrupts
  956. * @op: A pointer to the OpenFirmware device tree node associated
  957. * with the controller this EDAC instance is bound to.
  958. * @mci: A pointer to the EDAC memory controller instance
  959. * associated with the ibm,sdram-4xx-ddr2 controller for which
  960. * interrupts are being registered.
  961. *
  962. * This routine parses the correctable (CE) and uncorrectable error (UE)
  963. * interrupts from the device tree node and maps and assigns them to
  964. * the associated EDAC memory controller instance.
  965. *
  966. * Returns 0 if OK; otherwise, -ENODEV if the interrupts could not be
  967. * mapped and assigned.
  968. */
  969. static int __devinit
  970. ppc4xx_edac_register_irq(struct of_device *op, struct mem_ctl_info *mci)
  971. {
  972. int status = 0;
  973. int ded_irq, sec_irq;
  974. struct ppc4xx_edac_pdata *pdata = mci->pvt_info;
  975. struct device_node *np = op->node;
  976. ded_irq = irq_of_parse_and_map(np, INTMAP_ECCDED_INDEX);
  977. sec_irq = irq_of_parse_and_map(np, INTMAP_ECCSEC_INDEX);
  978. if (ded_irq == NO_IRQ || sec_irq == NO_IRQ) {
  979. ppc4xx_edac_mc_printk(KERN_ERR, mci,
  980. "Unable to map interrupts.\n");
  981. status = -ENODEV;
  982. goto fail;
  983. }
  984. status = request_irq(ded_irq,
  985. ppc4xx_edac_isr,
  986. IRQF_DISABLED,
  987. "[EDAC] MC ECCDED",
  988. mci);
  989. if (status < 0) {
  990. ppc4xx_edac_mc_printk(KERN_ERR, mci,
  991. "Unable to request irq %d for ECC DED",
  992. ded_irq);
  993. status = -ENODEV;
  994. goto fail1;
  995. }
  996. status = request_irq(sec_irq,
  997. ppc4xx_edac_isr,
  998. IRQF_DISABLED,
  999. "[EDAC] MC ECCSEC",
  1000. mci);
  1001. if (status < 0) {
  1002. ppc4xx_edac_mc_printk(KERN_ERR, mci,
  1003. "Unable to request irq %d for ECC SEC",
  1004. sec_irq);
  1005. status = -ENODEV;
  1006. goto fail2;
  1007. }
  1008. ppc4xx_edac_mc_printk(KERN_INFO, mci, "ECCDED irq is %d\n", ded_irq);
  1009. ppc4xx_edac_mc_printk(KERN_INFO, mci, "ECCSEC irq is %d\n", sec_irq);
  1010. pdata->irqs.ded = ded_irq;
  1011. pdata->irqs.sec = sec_irq;
  1012. return 0;
  1013. fail2:
  1014. free_irq(sec_irq, mci);
  1015. fail1:
  1016. free_irq(ded_irq, mci);
  1017. fail:
  1018. return status;
  1019. }
  1020. /**
  1021. * ppc4xx_edac_map_dcrs - locate and map controller registers
  1022. * @np: A pointer to the device tree node containing the DCR
  1023. * resources to map.
  1024. * @dcr_host: A pointer to the DCR data to populate with the
  1025. * DCR mapping.
  1026. *
  1027. * This routine attempts to locate in the device tree and map the DCR
  1028. * register resources associated with the controller's indirect DCR
  1029. * address and data windows.
  1030. *
  1031. * Returns 0 if the DCRs were successfully mapped; otherwise, < 0 on
  1032. * error.
  1033. */
  1034. static int __devinit
  1035. ppc4xx_edac_map_dcrs(const struct device_node *np, dcr_host_t *dcr_host)
  1036. {
  1037. unsigned int dcr_base, dcr_len;
  1038. if (np == NULL || dcr_host == NULL)
  1039. return -EINVAL;
  1040. /* Get the DCR resource extent and sanity check the values. */
  1041. dcr_base = dcr_resource_start(np, 0);
  1042. dcr_len = dcr_resource_len(np, 0);
  1043. if (dcr_base == 0 || dcr_len == 0) {
  1044. ppc4xx_edac_printk(KERN_ERR,
  1045. "Failed to obtain DCR property.\n");
  1046. return -ENODEV;
  1047. }
  1048. if (dcr_len != SDRAM_DCR_RESOURCE_LEN) {
  1049. ppc4xx_edac_printk(KERN_ERR,
  1050. "Unexpected DCR length %d, expected %d.\n",
  1051. dcr_len, SDRAM_DCR_RESOURCE_LEN);
  1052. return -ENODEV;
  1053. }
  1054. /* Attempt to map the DCR extent. */
  1055. *dcr_host = dcr_map(np, dcr_base, dcr_len);
  1056. if (!DCR_MAP_OK(*dcr_host)) {
  1057. ppc4xx_edac_printk(KERN_INFO, "Failed to map DCRs.\n");
  1058. return -ENODEV;
  1059. }
  1060. return 0;
  1061. }
  1062. /**
  1063. * ppc4xx_edac_probe - check controller and bind driver
  1064. * @op: A pointer to the OpenFirmware device tree node associated
  1065. * with the controller being probed for driver binding.
  1066. * @match: A pointer to the OpenFirmware device tree match
  1067. * information associated with the controller being probed
  1068. * for driver binding.
  1069. *
  1070. * This routine probes a specific ibm,sdram-4xx-ddr2 controller
  1071. * instance for binding with the driver.
  1072. *
  1073. * Returns 0 if the controller instance was successfully bound to the
  1074. * driver; otherwise, < 0 on error.
  1075. */
  1076. static int __devinit
  1077. ppc4xx_edac_probe(struct of_device *op, const struct of_device_id *match)
  1078. {
  1079. int status = 0;
  1080. u32 mcopt1, memcheck;
  1081. dcr_host_t dcr_host;
  1082. const struct device_node *np = op->node;
  1083. struct mem_ctl_info *mci = NULL;
  1084. static int ppc4xx_edac_instance;
  1085. /*
  1086. * At this point, we only support the controller realized on
  1087. * the AMCC PPC 405EX[r]. Reject anything else.
  1088. */
  1089. if (!of_device_is_compatible(np, "ibm,sdram-405ex") &&
  1090. !of_device_is_compatible(np, "ibm,sdram-405exr")) {
  1091. ppc4xx_edac_printk(KERN_NOTICE,
  1092. "Only the PPC405EX[r] is supported.\n");
  1093. return -ENODEV;
  1094. }
  1095. /*
  1096. * Next, get the DCR property and attempt to map it so that we
  1097. * can probe the controller.
  1098. */
  1099. status = ppc4xx_edac_map_dcrs(np, &dcr_host);
  1100. if (status)
  1101. return status;
  1102. /*
  1103. * First determine whether ECC is enabled at all. If not,
  1104. * there is no useful checking or monitoring that can be done
  1105. * for this controller.
  1106. */
  1107. mcopt1 = mfsdram(&dcr_host, SDRAM_MCOPT1);
  1108. memcheck = (mcopt1 & SDRAM_MCOPT1_MCHK_MASK);
  1109. if (memcheck == SDRAM_MCOPT1_MCHK_NON) {
  1110. ppc4xx_edac_printk(KERN_INFO, "%s: No ECC memory detected or "
  1111. "ECC is disabled.\n", np->full_name);
  1112. status = -ENODEV;
  1113. goto done;
  1114. }
  1115. /*
  1116. * At this point, we know ECC is enabled, allocate an EDAC
  1117. * controller instance and perform the appropriate
  1118. * initialization.
  1119. */
  1120. mci = edac_mc_alloc(sizeof(struct ppc4xx_edac_pdata),
  1121. ppc4xx_edac_nr_csrows,
  1122. ppc4xx_edac_nr_chans,
  1123. ppc4xx_edac_instance);
  1124. if (mci == NULL) {
  1125. ppc4xx_edac_printk(KERN_ERR, "%s: "
  1126. "Failed to allocate EDAC MC instance!\n",
  1127. np->full_name);
  1128. status = -ENOMEM;
  1129. goto done;
  1130. }
  1131. status = ppc4xx_edac_mc_init(mci, op, match, &dcr_host, mcopt1);
  1132. if (status) {
  1133. ppc4xx_edac_mc_printk(KERN_ERR, mci,
  1134. "Failed to initialize instance!\n");
  1135. goto fail;
  1136. }
  1137. /*
  1138. * We have a valid, initialized EDAC instance bound to the
  1139. * controller. Attempt to register it with the EDAC subsystem
  1140. * and, if necessary, register interrupts.
  1141. */
  1142. if (edac_mc_add_mc(mci)) {
  1143. ppc4xx_edac_mc_printk(KERN_ERR, mci,
  1144. "Failed to add instance!\n");
  1145. status = -ENODEV;
  1146. goto fail;
  1147. }
  1148. if (edac_op_state == EDAC_OPSTATE_INT) {
  1149. status = ppc4xx_edac_register_irq(op, mci);
  1150. if (status)
  1151. goto fail1;
  1152. }
  1153. ppc4xx_edac_instance++;
  1154. return 0;
  1155. fail1:
  1156. edac_mc_del_mc(mci->dev);
  1157. fail:
  1158. edac_mc_free(mci);
  1159. done:
  1160. return status;
  1161. }
  1162. /**
  1163. * ppc4xx_edac_remove - unbind driver from controller
  1164. * @op: A pointer to the OpenFirmware device tree node associated
  1165. * with the controller this EDAC instance is to be unbound/removed
  1166. * from.
  1167. *
  1168. * This routine unbinds the EDAC memory controller instance associated
  1169. * with the specified ibm,sdram-4xx-ddr2 controller described by the
  1170. * OpenFirmware device tree node passed as a parameter.
  1171. *
  1172. * Unconditionally returns 0.
  1173. */
  1174. static int
  1175. ppc4xx_edac_remove(struct of_device *op)
  1176. {
  1177. struct mem_ctl_info *mci = dev_get_drvdata(&op->dev);
  1178. struct ppc4xx_edac_pdata *pdata = mci->pvt_info;
  1179. if (edac_op_state == EDAC_OPSTATE_INT) {
  1180. free_irq(pdata->irqs.sec, mci);
  1181. free_irq(pdata->irqs.ded, mci);
  1182. }
  1183. dcr_unmap(pdata->dcr_host, SDRAM_DCR_RESOURCE_LEN);
  1184. edac_mc_del_mc(mci->dev);
  1185. edac_mc_free(mci);
  1186. return 0;
  1187. }
  1188. /**
  1189. * ppc4xx_edac_opstate_init - initialize EDAC reporting method
  1190. *
  1191. * This routine ensures that the EDAC memory controller reporting
  1192. * method is mapped to a sane value as the EDAC core defines the value
  1193. * to EDAC_OPSTATE_INVAL by default. We don't call the global
  1194. * opstate_init as that defaults to polling and we want interrupt as
  1195. * the default.
  1196. */
  1197. static inline void __init
  1198. ppc4xx_edac_opstate_init(void)
  1199. {
  1200. switch (edac_op_state) {
  1201. case EDAC_OPSTATE_POLL:
  1202. case EDAC_OPSTATE_INT:
  1203. break;
  1204. default:
  1205. edac_op_state = EDAC_OPSTATE_INT;
  1206. break;
  1207. }
  1208. ppc4xx_edac_printk(KERN_INFO, "Reporting type: %s\n",
  1209. ((edac_op_state == EDAC_OPSTATE_POLL) ?
  1210. EDAC_OPSTATE_POLL_STR :
  1211. ((edac_op_state == EDAC_OPSTATE_INT) ?
  1212. EDAC_OPSTATE_INT_STR :
  1213. EDAC_OPSTATE_UNKNOWN_STR)));
  1214. }
  1215. /**
  1216. * ppc4xx_edac_init - driver/module insertion entry point
  1217. *
  1218. * This routine is the driver/module insertion entry point. It
  1219. * initializes the EDAC memory controller reporting state and
  1220. * registers the driver as an OpenFirmware device tree platform
  1221. * driver.
  1222. */
  1223. static int __init
  1224. ppc4xx_edac_init(void)
  1225. {
  1226. ppc4xx_edac_printk(KERN_INFO, PPC4XX_EDAC_MODULE_REVISION "\n");
  1227. ppc4xx_edac_opstate_init();
  1228. return of_register_platform_driver(&ppc4xx_edac_driver);
  1229. }
  1230. /**
  1231. * ppc4xx_edac_exit - driver/module removal entry point
  1232. *
  1233. * This routine is the driver/module removal entry point. It
  1234. * unregisters the driver as an OpenFirmware device tree platform
  1235. * driver.
  1236. */
  1237. static void __exit
  1238. ppc4xx_edac_exit(void)
  1239. {
  1240. of_unregister_platform_driver(&ppc4xx_edac_driver);
  1241. }
  1242. module_init(ppc4xx_edac_init);
  1243. module_exit(ppc4xx_edac_exit);
  1244. MODULE_LICENSE("GPL v2");
  1245. MODULE_AUTHOR("Grant Erickson <gerickson@nuovations.com>");
  1246. MODULE_DESCRIPTION("EDAC MC Driver for the PPC4xx IBM DDR2 Memory Controller");
  1247. module_param(edac_op_state, int, 0444);
  1248. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting State: "
  1249. "0=" EDAC_OPSTATE_POLL_STR ", 2=" EDAC_OPSTATE_INT_STR);