i82975x_edac.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /*
  2. * Intel 82975X Memory Controller kernel module
  3. * (C) 2007 aCarLab (India) Pvt. Ltd. (http://acarlab.com)
  4. * (C) 2007 jetzbroadband (http://jetzbroadband.com)
  5. * This file may be distributed under the terms of the
  6. * GNU General Public License.
  7. *
  8. * Written by Arvind R.
  9. * Copied from i82875p_edac.c source:
  10. */
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/pci.h>
  14. #include <linux/pci_ids.h>
  15. #include <linux/edac.h>
  16. #include "edac_core.h"
  17. #define I82975X_REVISION " Ver: 1.0.0"
  18. #define EDAC_MOD_STR "i82975x_edac"
  19. #define i82975x_printk(level, fmt, arg...) \
  20. edac_printk(level, "i82975x", fmt, ##arg)
  21. #define i82975x_mc_printk(mci, level, fmt, arg...) \
  22. edac_mc_chipset_printk(mci, level, "i82975x", fmt, ##arg)
  23. #ifndef PCI_DEVICE_ID_INTEL_82975_0
  24. #define PCI_DEVICE_ID_INTEL_82975_0 0x277c
  25. #endif /* PCI_DEVICE_ID_INTEL_82975_0 */
  26. #define I82975X_NR_DIMMS 8
  27. #define I82975X_NR_CSROWS(nr_chans) (I82975X_NR_DIMMS / (nr_chans))
  28. /* Intel 82975X register addresses - device 0 function 0 - DRAM Controller */
  29. #define I82975X_EAP 0x58 /* Dram Error Address Pointer (32b)
  30. *
  31. * 31:7 128 byte cache-line address
  32. * 6:1 reserved
  33. * 0 0: CH0; 1: CH1
  34. */
  35. #define I82975X_DERRSYN 0x5c /* Dram Error SYNdrome (8b)
  36. *
  37. * 7:0 DRAM ECC Syndrome
  38. */
  39. #define I82975X_DES 0x5d /* Dram ERRor DeSTination (8b)
  40. * 0h: Processor Memory Reads
  41. * 1h:7h reserved
  42. * More - See Page 65 of Intel DocSheet.
  43. */
  44. #define I82975X_ERRSTS 0xc8 /* Error Status Register (16b)
  45. *
  46. * 15:12 reserved
  47. * 11 Thermal Sensor Event
  48. * 10 reserved
  49. * 9 non-DRAM lock error (ndlock)
  50. * 8 Refresh Timeout
  51. * 7:2 reserved
  52. * 1 ECC UE (multibit DRAM error)
  53. * 0 ECC CE (singlebit DRAM error)
  54. */
  55. /* Error Reporting is supported by 3 mechanisms:
  56. 1. DMI SERR generation ( ERRCMD )
  57. 2. SMI DMI generation ( SMICMD )
  58. 3. SCI DMI generation ( SCICMD )
  59. NOTE: Only ONE of the three must be enabled
  60. */
  61. #define I82975X_ERRCMD 0xca /* Error Command (16b)
  62. *
  63. * 15:12 reserved
  64. * 11 Thermal Sensor Event
  65. * 10 reserved
  66. * 9 non-DRAM lock error (ndlock)
  67. * 8 Refresh Timeout
  68. * 7:2 reserved
  69. * 1 ECC UE (multibit DRAM error)
  70. * 0 ECC CE (singlebit DRAM error)
  71. */
  72. #define I82975X_SMICMD 0xcc /* Error Command (16b)
  73. *
  74. * 15:2 reserved
  75. * 1 ECC UE (multibit DRAM error)
  76. * 0 ECC CE (singlebit DRAM error)
  77. */
  78. #define I82975X_SCICMD 0xce /* Error Command (16b)
  79. *
  80. * 15:2 reserved
  81. * 1 ECC UE (multibit DRAM error)
  82. * 0 ECC CE (singlebit DRAM error)
  83. */
  84. #define I82975X_XEAP 0xfc /* Extended Dram Error Address Pointer (8b)
  85. *
  86. * 7:1 reserved
  87. * 0 Bit32 of the Dram Error Address
  88. */
  89. #define I82975X_MCHBAR 0x44 /*
  90. *
  91. * 31:14 Base Addr of 16K memory-mapped
  92. * configuration space
  93. * 13:1 reserverd
  94. * 0 mem-mapped config space enable
  95. */
  96. /* NOTE: Following addresses have to indexed using MCHBAR offset (44h, 32b) */
  97. /* Intel 82975x memory mapped register space */
  98. #define I82975X_DRB_SHIFT 25 /* fixed 32MiB grain */
  99. #define I82975X_DRB 0x100 /* DRAM Row Boundary (8b x 8)
  100. *
  101. * 7 set to 1 in highest DRB of
  102. * channel if 4GB in ch.
  103. * 6:2 upper boundary of rank in
  104. * 32MB grains
  105. * 1:0 set to 0
  106. */
  107. #define I82975X_DRB_CH0R0 0x100
  108. #define I82975X_DRB_CH0R1 0x101
  109. #define I82975X_DRB_CH0R2 0x102
  110. #define I82975X_DRB_CH0R3 0x103
  111. #define I82975X_DRB_CH1R0 0x180
  112. #define I82975X_DRB_CH1R1 0x181
  113. #define I82975X_DRB_CH1R2 0x182
  114. #define I82975X_DRB_CH1R3 0x183
  115. #define I82975X_DRA 0x108 /* DRAM Row Attribute (4b x 8)
  116. * defines the PAGE SIZE to be used
  117. * for the rank
  118. * 7 reserved
  119. * 6:4 row attr of odd rank, i.e. 1
  120. * 3 reserved
  121. * 2:0 row attr of even rank, i.e. 0
  122. *
  123. * 000 = unpopulated
  124. * 001 = reserved
  125. * 010 = 4KiB
  126. * 011 = 8KiB
  127. * 100 = 16KiB
  128. * others = reserved
  129. */
  130. #define I82975X_DRA_CH0R01 0x108
  131. #define I82975X_DRA_CH0R23 0x109
  132. #define I82975X_DRA_CH1R01 0x188
  133. #define I82975X_DRA_CH1R23 0x189
  134. #define I82975X_BNKARC 0x10e /* Type of device in each rank - Bank Arch (16b)
  135. *
  136. * 15:8 reserved
  137. * 7:6 Rank 3 architecture
  138. * 5:4 Rank 2 architecture
  139. * 3:2 Rank 1 architecture
  140. * 1:0 Rank 0 architecture
  141. *
  142. * 00 => 4 banks
  143. * 01 => 8 banks
  144. */
  145. #define I82975X_C0BNKARC 0x10e
  146. #define I82975X_C1BNKARC 0x18e
  147. #define I82975X_DRC 0x120 /* DRAM Controller Mode0 (32b)
  148. *
  149. * 31:30 reserved
  150. * 29 init complete
  151. * 28:11 reserved, according to Intel
  152. * 22:21 number of channels
  153. * 00=1 01=2 in 82875
  154. * seems to be ECC mode
  155. * bits in 82975 in Asus
  156. * P5W
  157. * 19:18 Data Integ Mode
  158. * 00=none 01=ECC in 82875
  159. * 10:8 refresh mode
  160. * 7 reserved
  161. * 6:4 mode select
  162. * 3:2 reserved
  163. * 1:0 DRAM type 10=Second Revision
  164. * DDR2 SDRAM
  165. * 00, 01, 11 reserved
  166. */
  167. #define I82975X_DRC_CH0M0 0x120
  168. #define I82975X_DRC_CH1M0 0x1A0
  169. #define I82975X_DRC_M1 0x124 /* DRAM Controller Mode1 (32b)
  170. * 31 0=Standard Address Map
  171. * 1=Enhanced Address Map
  172. * 30:0 reserved
  173. */
  174. #define I82975X_DRC_CH0M1 0x124
  175. #define I82975X_DRC_CH1M1 0x1A4
  176. enum i82975x_chips {
  177. I82975X = 0,
  178. };
  179. struct i82975x_pvt {
  180. void __iomem *mch_window;
  181. };
  182. struct i82975x_dev_info {
  183. const char *ctl_name;
  184. };
  185. struct i82975x_error_info {
  186. u16 errsts;
  187. u32 eap;
  188. u8 des;
  189. u8 derrsyn;
  190. u16 errsts2;
  191. u8 chan; /* the channel is bit 0 of EAP */
  192. u8 xeap; /* extended eap bit */
  193. };
  194. static const struct i82975x_dev_info i82975x_devs[] = {
  195. [I82975X] = {
  196. .ctl_name = "i82975x"
  197. },
  198. };
  199. static struct pci_dev *mci_pdev; /* init dev: in case that AGP code has
  200. * already registered driver
  201. */
  202. static int i82975x_registered = 1;
  203. static void i82975x_get_error_info(struct mem_ctl_info *mci,
  204. struct i82975x_error_info *info)
  205. {
  206. struct pci_dev *pdev;
  207. pdev = to_pci_dev(mci->pdev);
  208. /*
  209. * This is a mess because there is no atomic way to read all the
  210. * registers at once and the registers can transition from CE being
  211. * overwritten by UE.
  212. */
  213. pci_read_config_word(pdev, I82975X_ERRSTS, &info->errsts);
  214. pci_read_config_dword(pdev, I82975X_EAP, &info->eap);
  215. pci_read_config_byte(pdev, I82975X_XEAP, &info->xeap);
  216. pci_read_config_byte(pdev, I82975X_DES, &info->des);
  217. pci_read_config_byte(pdev, I82975X_DERRSYN, &info->derrsyn);
  218. pci_read_config_word(pdev, I82975X_ERRSTS, &info->errsts2);
  219. pci_write_bits16(pdev, I82975X_ERRSTS, 0x0003, 0x0003);
  220. /*
  221. * If the error is the same then we can for both reads then
  222. * the first set of reads is valid. If there is a change then
  223. * there is a CE no info and the second set of reads is valid
  224. * and should be UE info.
  225. */
  226. if (!(info->errsts2 & 0x0003))
  227. return;
  228. if ((info->errsts ^ info->errsts2) & 0x0003) {
  229. pci_read_config_dword(pdev, I82975X_EAP, &info->eap);
  230. pci_read_config_byte(pdev, I82975X_XEAP, &info->xeap);
  231. pci_read_config_byte(pdev, I82975X_DES, &info->des);
  232. pci_read_config_byte(pdev, I82975X_DERRSYN,
  233. &info->derrsyn);
  234. }
  235. }
  236. static int i82975x_process_error_info(struct mem_ctl_info *mci,
  237. struct i82975x_error_info *info, int handle_errors)
  238. {
  239. int row, chan;
  240. unsigned long offst, page;
  241. if (!(info->errsts2 & 0x0003))
  242. return 0;
  243. if (!handle_errors)
  244. return 1;
  245. if ((info->errsts ^ info->errsts2) & 0x0003) {
  246. edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1, 0, 0, 0,
  247. -1, -1, -1, "UE overwrote CE", "");
  248. info->errsts = info->errsts2;
  249. }
  250. page = (unsigned long) info->eap;
  251. page >>= 1;
  252. if (info->xeap & 1)
  253. page |= 0x80000000;
  254. page >>= (PAGE_SHIFT - 1);
  255. row = edac_mc_find_csrow_by_page(mci, page);
  256. if (row == -1) {
  257. i82975x_mc_printk(mci, KERN_ERR, "error processing EAP:\n"
  258. "\tXEAP=%u\n"
  259. "\t EAP=0x%08x\n"
  260. "\tPAGE=0x%08x\n",
  261. (info->xeap & 1) ? 1 : 0, info->eap, (unsigned int) page);
  262. return 0;
  263. }
  264. chan = (mci->csrows[row]->nr_channels == 1) ? 0 : info->eap & 1;
  265. offst = info->eap
  266. & ((1 << PAGE_SHIFT) -
  267. (1 << mci->csrows[row]->channels[chan]->dimm->grain));
  268. if (info->errsts & 0x0002)
  269. edac_mc_handle_error(HW_EVENT_ERR_UNCORRECTED, mci, 1,
  270. page, offst, 0,
  271. row, -1, -1,
  272. "i82975x UE", "");
  273. else
  274. edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, 1,
  275. page, offst, info->derrsyn,
  276. row, chan ? chan : 0, -1,
  277. "i82975x CE", "");
  278. return 1;
  279. }
  280. static void i82975x_check(struct mem_ctl_info *mci)
  281. {
  282. struct i82975x_error_info info;
  283. edac_dbg(1, "MC%d\n", mci->mc_idx);
  284. i82975x_get_error_info(mci, &info);
  285. i82975x_process_error_info(mci, &info, 1);
  286. }
  287. /* Return 1 if dual channel mode is active. Else return 0. */
  288. static int dual_channel_active(void __iomem *mch_window)
  289. {
  290. /*
  291. * We treat interleaved-symmetric configuration as dual-channel - EAP's
  292. * bit-0 giving the channel of the error location.
  293. *
  294. * All other configurations are treated as single channel - the EAP's
  295. * bit-0 will resolve ok in symmetric area of mixed
  296. * (symmetric/asymmetric) configurations
  297. */
  298. u8 drb[4][2];
  299. int row;
  300. int dualch;
  301. for (dualch = 1, row = 0; dualch && (row < 4); row++) {
  302. drb[row][0] = readb(mch_window + I82975X_DRB + row);
  303. drb[row][1] = readb(mch_window + I82975X_DRB + row + 0x80);
  304. dualch = dualch && (drb[row][0] == drb[row][1]);
  305. }
  306. return dualch;
  307. }
  308. static enum dev_type i82975x_dram_type(void __iomem *mch_window, int rank)
  309. {
  310. /*
  311. * ECC is possible on i92975x ONLY with DEV_X8
  312. */
  313. return DEV_X8;
  314. }
  315. static void i82975x_init_csrows(struct mem_ctl_info *mci,
  316. struct pci_dev *pdev, void __iomem *mch_window)
  317. {
  318. struct csrow_info *csrow;
  319. unsigned long last_cumul_size;
  320. u8 value;
  321. u32 cumul_size, nr_pages;
  322. int index, chan;
  323. struct dimm_info *dimm;
  324. enum dev_type dtype;
  325. last_cumul_size = 0;
  326. /*
  327. * 82875 comment:
  328. * The dram row boundary (DRB) reg values are boundary address
  329. * for each DRAM row with a granularity of 32 or 64MB (single/dual
  330. * channel operation). DRB regs are cumulative; therefore DRB7 will
  331. * contain the total memory contained in all rows.
  332. *
  333. */
  334. for (index = 0; index < mci->nr_csrows; index++) {
  335. csrow = mci->csrows[index];
  336. value = readb(mch_window + I82975X_DRB + index +
  337. ((index >= 4) ? 0x80 : 0));
  338. cumul_size = value;
  339. cumul_size <<= (I82975X_DRB_SHIFT - PAGE_SHIFT);
  340. /*
  341. * Adjust cumul_size w.r.t number of channels
  342. *
  343. */
  344. if (csrow->nr_channels > 1)
  345. cumul_size <<= 1;
  346. edac_dbg(3, "(%d) cumul_size 0x%x\n", index, cumul_size);
  347. nr_pages = cumul_size - last_cumul_size;
  348. if (!nr_pages)
  349. continue;
  350. /*
  351. * Initialise dram labels
  352. * index values:
  353. * [0-7] for single-channel; i.e. csrow->nr_channels = 1
  354. * [0-3] for dual-channel; i.e. csrow->nr_channels = 2
  355. */
  356. dtype = i82975x_dram_type(mch_window, index);
  357. for (chan = 0; chan < csrow->nr_channels; chan++) {
  358. dimm = mci->csrows[index]->channels[chan]->dimm;
  359. dimm->nr_pages = nr_pages / csrow->nr_channels;
  360. snprintf(csrow->channels[chan]->dimm->label, EDAC_MC_LABEL_LEN, "DIMM %c%d",
  361. (chan == 0) ? 'A' : 'B',
  362. index);
  363. dimm->grain = 1 << 7; /* 128Byte cache-line resolution */
  364. dimm->dtype = i82975x_dram_type(mch_window, index);
  365. dimm->mtype = MEM_DDR2; /* I82975x supports only DDR2 */
  366. dimm->edac_mode = EDAC_SECDED; /* only supported */
  367. }
  368. csrow->first_page = last_cumul_size;
  369. csrow->last_page = cumul_size - 1;
  370. last_cumul_size = cumul_size;
  371. }
  372. }
  373. /* #define i82975x_DEBUG_IOMEM */
  374. #ifdef i82975x_DEBUG_IOMEM
  375. static void i82975x_print_dram_timings(void __iomem *mch_window)
  376. {
  377. /*
  378. * The register meanings are from Intel specs;
  379. * (shows 13-5-5-5 for 800-DDR2)
  380. * Asus P5W Bios reports 15-5-4-4
  381. * What's your religion?
  382. */
  383. static const int caslats[4] = { 5, 4, 3, 6 };
  384. u32 dtreg[2];
  385. dtreg[0] = readl(mch_window + 0x114);
  386. dtreg[1] = readl(mch_window + 0x194);
  387. i82975x_printk(KERN_INFO, "DRAM Timings : Ch0 Ch1\n"
  388. " RAS Active Min = %d %d\n"
  389. " CAS latency = %d %d\n"
  390. " RAS to CAS = %d %d\n"
  391. " RAS precharge = %d %d\n",
  392. (dtreg[0] >> 19 ) & 0x0f,
  393. (dtreg[1] >> 19) & 0x0f,
  394. caslats[(dtreg[0] >> 8) & 0x03],
  395. caslats[(dtreg[1] >> 8) & 0x03],
  396. ((dtreg[0] >> 4) & 0x07) + 2,
  397. ((dtreg[1] >> 4) & 0x07) + 2,
  398. (dtreg[0] & 0x07) + 2,
  399. (dtreg[1] & 0x07) + 2
  400. );
  401. }
  402. #endif
  403. static int i82975x_probe1(struct pci_dev *pdev, int dev_idx)
  404. {
  405. int rc = -ENODEV;
  406. struct mem_ctl_info *mci;
  407. struct edac_mc_layer layers[2];
  408. struct i82975x_pvt *pvt;
  409. void __iomem *mch_window;
  410. u32 mchbar;
  411. u32 drc[2];
  412. struct i82975x_error_info discard;
  413. int chans;
  414. #ifdef i82975x_DEBUG_IOMEM
  415. u8 c0drb[4];
  416. u8 c1drb[4];
  417. #endif
  418. edac_dbg(0, "\n");
  419. pci_read_config_dword(pdev, I82975X_MCHBAR, &mchbar);
  420. if (!(mchbar & 1)) {
  421. edac_dbg(3, "failed, MCHBAR disabled!\n");
  422. goto fail0;
  423. }
  424. mchbar &= 0xffffc000; /* bits 31:14 used for 16K window */
  425. mch_window = ioremap_nocache(mchbar, 0x1000);
  426. #ifdef i82975x_DEBUG_IOMEM
  427. i82975x_printk(KERN_INFO, "MCHBAR real = %0x, remapped = %p\n",
  428. mchbar, mch_window);
  429. c0drb[0] = readb(mch_window + I82975X_DRB_CH0R0);
  430. c0drb[1] = readb(mch_window + I82975X_DRB_CH0R1);
  431. c0drb[2] = readb(mch_window + I82975X_DRB_CH0R2);
  432. c0drb[3] = readb(mch_window + I82975X_DRB_CH0R3);
  433. c1drb[0] = readb(mch_window + I82975X_DRB_CH1R0);
  434. c1drb[1] = readb(mch_window + I82975X_DRB_CH1R1);
  435. c1drb[2] = readb(mch_window + I82975X_DRB_CH1R2);
  436. c1drb[3] = readb(mch_window + I82975X_DRB_CH1R3);
  437. i82975x_printk(KERN_INFO, "DRBCH0R0 = 0x%02x\n", c0drb[0]);
  438. i82975x_printk(KERN_INFO, "DRBCH0R1 = 0x%02x\n", c0drb[1]);
  439. i82975x_printk(KERN_INFO, "DRBCH0R2 = 0x%02x\n", c0drb[2]);
  440. i82975x_printk(KERN_INFO, "DRBCH0R3 = 0x%02x\n", c0drb[3]);
  441. i82975x_printk(KERN_INFO, "DRBCH1R0 = 0x%02x\n", c1drb[0]);
  442. i82975x_printk(KERN_INFO, "DRBCH1R1 = 0x%02x\n", c1drb[1]);
  443. i82975x_printk(KERN_INFO, "DRBCH1R2 = 0x%02x\n", c1drb[2]);
  444. i82975x_printk(KERN_INFO, "DRBCH1R3 = 0x%02x\n", c1drb[3]);
  445. #endif
  446. drc[0] = readl(mch_window + I82975X_DRC_CH0M0);
  447. drc[1] = readl(mch_window + I82975X_DRC_CH1M0);
  448. #ifdef i82975x_DEBUG_IOMEM
  449. i82975x_printk(KERN_INFO, "DRC_CH0 = %0x, %s\n", drc[0],
  450. ((drc[0] >> 21) & 3) == 1 ?
  451. "ECC enabled" : "ECC disabled");
  452. i82975x_printk(KERN_INFO, "DRC_CH1 = %0x, %s\n", drc[1],
  453. ((drc[1] >> 21) & 3) == 1 ?
  454. "ECC enabled" : "ECC disabled");
  455. i82975x_printk(KERN_INFO, "C0 BNKARC = %0x\n",
  456. readw(mch_window + I82975X_C0BNKARC));
  457. i82975x_printk(KERN_INFO, "C1 BNKARC = %0x\n",
  458. readw(mch_window + I82975X_C1BNKARC));
  459. i82975x_print_dram_timings(mch_window);
  460. goto fail1;
  461. #endif
  462. if (!(((drc[0] >> 21) & 3) == 1 || ((drc[1] >> 21) & 3) == 1)) {
  463. i82975x_printk(KERN_INFO, "ECC disabled on both channels.\n");
  464. goto fail1;
  465. }
  466. chans = dual_channel_active(mch_window) + 1;
  467. /* assuming only one controller, index thus is 0 */
  468. layers[0].type = EDAC_MC_LAYER_CHIP_SELECT;
  469. layers[0].size = I82975X_NR_DIMMS;
  470. layers[0].is_virt_csrow = true;
  471. layers[1].type = EDAC_MC_LAYER_CHANNEL;
  472. layers[1].size = I82975X_NR_CSROWS(chans);
  473. layers[1].is_virt_csrow = false;
  474. mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(*pvt));
  475. if (!mci) {
  476. rc = -ENOMEM;
  477. goto fail1;
  478. }
  479. edac_dbg(3, "init mci\n");
  480. mci->pdev = &pdev->dev;
  481. mci->mtype_cap = MEM_FLAG_DDR2;
  482. mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
  483. mci->edac_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
  484. mci->mod_name = EDAC_MOD_STR;
  485. mci->mod_ver = I82975X_REVISION;
  486. mci->ctl_name = i82975x_devs[dev_idx].ctl_name;
  487. mci->dev_name = pci_name(pdev);
  488. mci->edac_check = i82975x_check;
  489. mci->ctl_page_to_phys = NULL;
  490. edac_dbg(3, "init pvt\n");
  491. pvt = (struct i82975x_pvt *) mci->pvt_info;
  492. pvt->mch_window = mch_window;
  493. i82975x_init_csrows(mci, pdev, mch_window);
  494. mci->scrub_mode = SCRUB_HW_SRC;
  495. i82975x_get_error_info(mci, &discard); /* clear counters */
  496. /* finalize this instance of memory controller with edac core */
  497. if (edac_mc_add_mc(mci)) {
  498. edac_dbg(3, "failed edac_mc_add_mc()\n");
  499. goto fail2;
  500. }
  501. /* get this far and it's successful */
  502. edac_dbg(3, "success\n");
  503. return 0;
  504. fail2:
  505. edac_mc_free(mci);
  506. fail1:
  507. iounmap(mch_window);
  508. fail0:
  509. return rc;
  510. }
  511. /* returns count (>= 0), or negative on error */
  512. static int i82975x_init_one(struct pci_dev *pdev,
  513. const struct pci_device_id *ent)
  514. {
  515. int rc;
  516. edac_dbg(0, "\n");
  517. if (pci_enable_device(pdev) < 0)
  518. return -EIO;
  519. rc = i82975x_probe1(pdev, ent->driver_data);
  520. if (mci_pdev == NULL)
  521. mci_pdev = pci_dev_get(pdev);
  522. return rc;
  523. }
  524. static void i82975x_remove_one(struct pci_dev *pdev)
  525. {
  526. struct mem_ctl_info *mci;
  527. struct i82975x_pvt *pvt;
  528. edac_dbg(0, "\n");
  529. mci = edac_mc_del_mc(&pdev->dev);
  530. if (mci == NULL)
  531. return;
  532. pvt = mci->pvt_info;
  533. if (pvt->mch_window)
  534. iounmap( pvt->mch_window );
  535. edac_mc_free(mci);
  536. }
  537. static const struct pci_device_id i82975x_pci_tbl[] = {
  538. {
  539. PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  540. I82975X
  541. },
  542. {
  543. 0,
  544. } /* 0 terminated list. */
  545. };
  546. MODULE_DEVICE_TABLE(pci, i82975x_pci_tbl);
  547. static struct pci_driver i82975x_driver = {
  548. .name = EDAC_MOD_STR,
  549. .probe = i82975x_init_one,
  550. .remove = i82975x_remove_one,
  551. .id_table = i82975x_pci_tbl,
  552. };
  553. static int __init i82975x_init(void)
  554. {
  555. int pci_rc;
  556. edac_dbg(3, "\n");
  557. /* Ensure that the OPSTATE is set correctly for POLL or NMI */
  558. opstate_init();
  559. pci_rc = pci_register_driver(&i82975x_driver);
  560. if (pci_rc < 0)
  561. goto fail0;
  562. if (mci_pdev == NULL) {
  563. mci_pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  564. PCI_DEVICE_ID_INTEL_82975_0, NULL);
  565. if (!mci_pdev) {
  566. edac_dbg(0, "i82975x pci_get_device fail\n");
  567. pci_rc = -ENODEV;
  568. goto fail1;
  569. }
  570. pci_rc = i82975x_init_one(mci_pdev, i82975x_pci_tbl);
  571. if (pci_rc < 0) {
  572. edac_dbg(0, "i82975x init fail\n");
  573. pci_rc = -ENODEV;
  574. goto fail1;
  575. }
  576. }
  577. return 0;
  578. fail1:
  579. pci_unregister_driver(&i82975x_driver);
  580. fail0:
  581. pci_dev_put(mci_pdev);
  582. return pci_rc;
  583. }
  584. static void __exit i82975x_exit(void)
  585. {
  586. edac_dbg(3, "\n");
  587. pci_unregister_driver(&i82975x_driver);
  588. if (!i82975x_registered) {
  589. i82975x_remove_one(mci_pdev);
  590. pci_dev_put(mci_pdev);
  591. }
  592. }
  593. module_init(i82975x_init);
  594. module_exit(i82975x_exit);
  595. MODULE_LICENSE("GPL");
  596. MODULE_AUTHOR("Arvind R. <arvino55@gmail.com>");
  597. MODULE_DESCRIPTION("MC support for Intel 82975 memory hub controllers");
  598. module_param(edac_op_state, int, 0444);
  599. MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");